Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Date: Thu, 18 Feb 2016 13:33:34 -0500
From: Rich Felker <>
Subject: Re: dynlink.c: bug in reclaim_gaps leading to segfault in

On Thu, Feb 18, 2016 at 07:05:13PM +0100, Szabolcs Nagy wrote:
> * Szabolcs Nagy <> [2016-02-17 11:19:17 +0100]:
> > * Timo Teras <> [2016-02-17 09:03:27 +0200]:
> > > Well - musl really should introduce __donatemem or similar for this
> > > purpose, and not overload the standard free() function. This would make
> > > the valgrind warning go away.
> > 
> > to please valgrind the options are
> > 
> > 1) have an internal free which valgrind does not know
> >    about, but public free calls it, so all public calls
> >    of free would go through an extra indirection.
> > 
> > 2) have a copy of the internal logic of free under a
> >    different name, which means maintenance work and
> >    code size increase.
> > 
> > 3) or have a suppression file.
> > 
> > i think 3) is a reasonable solution.
> i looked at this again: i think moving most of reclaim()
> function into src/malloc makes sense, so all malloc
> internal knowledge is at one place (even if dynlink.c
> is the only user of this code).
> but i don't see an easy way to do the reclaim without
> calling free (so the valgrind problem is not solved,
> only code maintenance gets better)

I think it could be done by making free a wrapper with zero cost. See
how free starts out with:

	if (!p) return;

This could instead be:

	if (p) return do_free(p);
	/* end of function */

and the return statement is just a conditional tail-call jump, same
cost as the conditional branch in the current code.

This would also fix malloc-internal calls to free (which might confuse
valgrind?) and eliminate the useless branch to test for null pointer
when free is called internally from malloc/realloc.


Powered by blists - more mailing lists

Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.