joyent/libuv — pull request #1048 by alexcrichton (2013-12-17 21:09:20+00:00)
Title: osx: Fix a memory leak in uv_fs_readdir()

On OSX, apparently directories with 0 files in them still allocate memory on
the invocation of `scandir`, so if the function returns early it ends up
leaking memory allocated in `scandir`. I have altered uv__fs_readdir to
instead go to the "deallocation exit area" when 0 files are found in the
directory, and continue to return early on a return value of -1.

I went to add a test for this functionality, but it appears that one already
exists (reading an empty directory), so I imagine that the valgrind builds
must only be happening on linux instead of OSX as well? I have confirmed
manually that a program without this fix will infinitely leak memory, and with
this fix the memory usage stays constant.