newlib cvs opendir family leaks?

Joel Sherrill joel.sherrill@oarcorp.com
Mon Nov 24 19:53:00 GMT 2008


Hi,

I found the problem.  scandir() does not call closedir()
on any error path.  I also question whether it is
safe to assume that malloc(0) returns NULL

Attached is the RTEMS version which is based
upon the one from newlib 1.8.0.  Look at where
the RTEMS version has "goto cleanup_and_bail;"
It also looks like the current newlib version may
be leaking memory based upon the RTEMS version.

I  think it would be more obvious to check
stb.st_size == 0 and return explicitly rather
than doing math and then calling malloc(0).

Now the question is how do you guys
want to fix it.  Is the "goto cleanup and bail"
approach ok since there are so many exit
paths and so much to potentially clean?

--joel


Joel Sherrill wrote:
> Hi,
>
> Just a heads up in case someone can identify
> this before I do.  The RTEMS readdir() test
> fails after switching to newlib's readdir() family.
> I have tracked this down to the newlib implementation
> leaking file descriptors.
>
> With RTEMS, we configure a hard limit on the number
> of concurrent open file descriptors.
>
> I tried to desk check this out but didn't spot it.
> I am working on it but hoped someone might see
> something wrong in the code.
>
> Thanks.
>
>   


-- 
Joel Sherrill, Ph.D.             Director of Research & Development
joel.sherrill@OARcorp.com        On-Line Applications Research
Ask me about RTEMS: a free RTOS  Huntsville AL 35805
   Support Available             (256) 722-9985


-------------- next part --------------
A non-text attachment was scrubbed...
Name: scandir.c
Type: text/x-csrc
Size: 5157 bytes
Desc: not available
URL: <http://sourceware.org/pipermail/newlib/attachments/20081124/89bfeb7f/attachment.bin>


More information about the Newlib mailing list