[eio] Fix memory leak in eio__scandir()

Ben Noordhuis info at bnoordhuis.nl
Mon Sep 12 17:28:36 CEST 2011


eio__scandir() leaks memory when opendir() returns NULL. It sets
req->result == -1 but doesn't free the memory it allocates.

Attached are two patches (different takes, same solution) that fix
that: one tries to be brief, the other minimally intrusive. The brief
one has a return statement in the middle of the function. Not all
people like that, hence the two takes. Pick the one you like best.

Apropos, two things I noticed about eio__scandir() is that it:

1. doesn't set req->errorno when opendir() fails (both patches fix that), and

2. uses readdir(), which is not guaranteed to be thread-safe. glibc
wraps it in a mutex and I think sunos's libc does so too but
readdir_r() is what should be used, really.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-Fix-memory-leak-in-eio__scandir.patch
Type: text/x-patch
Size: 983 bytes
Desc: not available
URL: <http://lists.schmorp.de/pipermail/libev/attachments/20110912/0617077c/attachment.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-Fix-memory-leak-in-eio__scandir-take2.patch
Type: text/x-patch
Size: 835 bytes
Desc: not available
URL: <http://lists.schmorp.de/pipermail/libev/attachments/20110912/0617077c/attachment-0001.bin>


More information about the libev mailing list