[patch] fix invalid free() in HEAD's readlink.c; take two

Bernhard Fischer rep.nop at aon.at
Mon Sep 12 19:21:36 UTC 2005


Rob Landley wrote:
> On Sunday 11 September 2005 04:42, Bernhard Fischer wrote:

> > Attached patch should be correct.
> >
> > - free the buffer allocated by xreadlink(), i.e. when
> >   CONFIG_FEATURE_READLINK_FOLLOW isn't set or no -f was given.
> 
> Except that xreadlink is returning malloced (well, realloced) memory
> that 
> you're now not freeing...

hm? i said:
-       if (ENABLE_FEATURE_CLEAN_UP) free(buf);
+       if (ENABLE_FEATURE_CLEAN_UP) {
+               if (!(opt & READLINK_FLAG_f))
+                       free(buf);
+       }

which did only free the memory allocated by xreadlink(), so that was
correct, i think. But anyway.
> 
> I took a whack at it, taking advantage of glibc's ability to malloc
> memory in 
> realpath and cleaning up the #ifdefs while I was there.  Tell me what
> you 
> think...

In this particular case of realpath i'd prefer not to rely on the
underlying libc but to use RESERVE_CONFIG_BUFFER there.

thank you,



More information about the busybox mailing list