[PATCH] res_query: fix for CNAME responses on A queries.

Rob Landley rob at landley.net
Sat Nov 28 07:29:37 UTC 2009


On Saturday 28 November 2009 01:06:30 Kevin Day wrote:
> On Fri, Nov 27, 2009 at 2:45 PM, Rob Landley <rob at landley.net> wrote:
> > On Friday 27 November 2009 11:45:50 Kevin Day wrote:
> >> I was looking at uClibc 0.9.28.3 to try and apply this patch and
> >> noticed:
> >>
> >> At the very end of your patch, the untouched code only has
> >> free(packet); while 0.9.28.3 has:
> >>         if (packet)
> >>                 free(packet);
> >>
> >> Does anybody know why was this safety check removed?
> >
> > From the Single Unix Specification version 4 (I.E. SUSv4, I.E. POSIX
> > 2008):
> >
> >  http://www.opengroup.org/onlinepubs/9699919799/functions/free.html
> >
> >  > If ptr is a null pointer, no action shall occur.
> >
> > I.E. free() has a null check built-in, as required by POSIX.
> >
> > Rob
> > --
> > Latency is more important than throughput. It's that simple. - Linus
> > Torvalds
>
> So you are saying a double-free cannot happen here?

I'm saying that freeing a NULL pointer is a NOP, so testing for NULL before 
calling free() is a waste of bytes.

What does a double-free have to do with this?  If the pointer is NULL, then 
there's nothing to free.  If the pointer isn't NULL, the test isn't relevant.

Legal (and pointless) code:

void does_nothing(void)
{
  x=NULL;

  free(x);
  free(x);
  free(x);
}

Rob
-- 
Latency is more important than throughput. It's that simple. - Linus Torvalds


More information about the uClibc mailing list