This is the mail archive of the mailing list for the newlib project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: scandir leak patch

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 <>

* 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        On-Line Applications Research
Ask me about RTEMS: a free RTOS  Huntsville AL 35805
  Support Available             (256) 722-9985

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]