This is the mail archive of the
newlib@sourceware.org
mailing list for the newlib project.
Re: scandir leak patch
- From: Joel Sherrill <joel dot sherrill at oarcorp dot com>
- To: Jeff Johnston <jjohnstn at redhat dot com>
- Cc: "newlib at sources dot redhat dot com" <newlib at sources dot redhat dot com>
- Date: Mon, 24 Nov 2008 14:17:27 -0600
- Subject: Re: scandir leak patch
- References: <492B01D5.1090307@oarcorp.com> <492B094C.50406@redhat.com>
Jeff Johnston wrote:
Joel Sherrill wrote:
Attached is the current newlib scandir.c with
the "goto cleanup_and_bail" modification from
the RTEMS one plus an explicit check for 0
entries from the fstat.
How does this look?
2008-11-24 Joel Sherrill <joel.sherrill@oarcorp.com>
* libc/posix/scandir.c: Fix memory leaks.
Hi Joel,
Thanks. I did some cleanup of your patch. First of all you should
have been using reallocf instead of realloc
since you reset the input pointer.
Wasn't it just realloc in CVS?
What's the rule to follow? I don't see reallocf() Linux man pages.
Secondly I wasn't thrilled with the
cleanup_and_bail section occurring after the normal return so I added a
flag to indicate "if successful" and used it so there would only be the
one return statement. Let me know if I missed anything or whether you
have any problems with the modifications.
That's fine. Accomplishes the same thing. I like yours. The
only solution I don't like is the one that duplicates that code
every exit path.
I have attached a new diff which would be applied to the original
scandir.c.
Looks fine to me. I am surprised this got noticed and fixed
in the RTEMS copy of scandir.c from newlib 1.8 and never
got spotted in newlib. That is a LONG time (16-8 == 8 years!!!)
-- Jeff J.
--
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