Avoid libuv resource leaks (fixes #395)