mailing list of musl libc
 help / color / mirror / code / Atom feed
From: Rich Felker <dalias@libc.org>
To: musl@lists.openwall.com
Subject: Re: dynlink.c: bug in reclaim_gaps leading to segfault in __libc_exit_fini
Date: Thu, 18 Feb 2016 13:33:34 -0500	[thread overview]
Message-ID: <20160218183333.GE9349@brightrain.aerifal.cx> (raw)
In-Reply-To: <20160218180513.GA3969@port70.net>

On Thu, Feb 18, 2016 at 07:05:13PM +0100, Szabolcs Nagy wrote:
> * Szabolcs Nagy <nsz@port70.net> [2016-02-17 11:19:17 +0100]:
> > * Timo Teras <timo.teras@iki.fi> [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.

Rich


  reply	other threads:[~2016-02-18 18:33 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-02-16 21:30 Hugues Bruant
2016-02-16 21:55 ` Szabolcs Nagy
2016-02-16 22:02   ` Rich Felker
2016-02-17  0:05   ` Hugues Bruant
2016-02-17  0:21     ` Rich Felker
2016-02-17  6:16       ` Hugues Bruant
2016-02-17  6:27         ` Hugues Bruant
2016-02-17  7:03   ` Timo Teras
2016-02-17  9:15     ` Hugues Bruant
2016-02-17 15:25       ` Rich Felker
2016-02-17 17:34         ` Hugues Bruant
2016-02-17 18:14           ` Szabolcs Nagy
2016-02-17 18:46             ` Isaac Dunham
2016-02-17 10:19     ` Szabolcs Nagy
2016-02-18 18:05       ` Szabolcs Nagy
2016-02-18 18:33         ` Rich Felker [this message]
2016-02-17 15:17     ` Markus Wichmann

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20160218183333.GE9349@brightrain.aerifal.cx \
    --to=dalias@libc.org \
    --cc=musl@lists.openwall.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).