git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH 2/2] Use xmemdup in many places.

From
Pierre Habouzit <madcoder@debian.org>
Date
Sep 19, 2007, 08:26 UTC
Message-ID
<20070919082611.GE28205@artemis.corp>
In-Reply-To
<7v6427qdqr.fsf@gitster.siamese.dyndns.org>
On Wed, Sep 19, 2007 at 08:08:12AM +0000, Junio C Hamano wrote:
Show 46 quoted lines
> Pierre Habouzit <madcoder@debian.org> writes:
> 
> > Signed-off-by: Pierre Habouzit <madcoder@debian.org>
> > ---
> >  attr.c                  |    7 +------
> >  builtin-add.c           |    8 ++------
> >  builtin-apply.c         |   11 ++---------
> >  builtin-fetch--tool.c   |    6 +-----
> >  builtin-fmt-merge-msg.c |   17 ++++++-----------
> >  builtin-for-each-ref.c  |   40 +++++++++-------------------------------
> >  builtin-log.c           |   12 ++----------
> >  builtin-ls-files.c      |    9 +--------
> >  builtin-mv.c            |    5 +----
> >  builtin-revert.c        |    4 +---
> >  builtin-shortlog.c      |   11 ++---------
> >  commit.c                |   16 ++++++----------
> >  connect.c               |    4 +---
> >  convert.c               |    7 +------
> >  diff.c                  |   13 ++-----------
> >  diffcore-order.c        |    7 ++-----
> >  fast-import.c           |    4 +---
> >  http-push.c             |    9 ++-------
> >  imap-send.c             |   20 +++++---------------
> >  merge-recursive.c       |   19 ++++---------------
> >  refs.c                  |   12 ++++--------
> >  sha1_file.c             |   12 +++---------
> >  tag.c                   |    4 +---
> >  23 files changed, 60 insertions(+), 197 deletions(-)
> > ...
> > diff --git a/builtin-apply.c b/builtin-apply.c
> > index 05011bb..900d0a7 100644
> > --- a/builtin-apply.c
> > +++ b/builtin-apply.c
> > @@ -293,11 +293,7 @@ static char *find_name(const char *line, char *def, int p_value, int terminate)
> >  			return def;
> >  	}
> >  
> > -	name = xmalloc(len + 1);
> > -	memcpy(name, start, len);
> > -	name[len] = 0;
> > -	free(def);
> > -	return name;
> > +	return xmemdup(start, len);
> >  }
> 
> Did we start leaking "def" here? 
  Hmm I fear we are. that has to be fixed indeed.
-- 
·O·  Pierre Habouzit
··O                                                madcoder@debian.org
OOO                                                http://www.madism.org
Previous: Junio C HamanoNext: Pierre Habouzit
Message 5 of 8 in “xmemdup patches”
  1. Pierre HabouzitSep 17, 2007
  2. 1/2 Add xmemdup that duplicates a block of memory, and NUL terminates it.Pierre Habouzit, Sep 15, 2007
  3. 2/2 Use xmemdup in many places.Pierre Habouzit, Sep 15, 2007
  4. Junio C HamanoSep 19, 2007
  5. Pierre HabouzitSep 19, 2007
  6. Pierre HabouzitSep 17, 2007
  7. Johannes SchindelinSep 17, 2007
  8. Pierre HabouzitSep 17, 2007

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.