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

Re: [PATCH 01/11] Fix memory leak in traverse_commit_list

From
Shawn O. Pearce <spearce@spearce.org>
Date
Nov 11, 2007, 05:17 UTC
Message-ID
<20071111051742.GT14735@spearce.org>
In-Reply-To
<7vmytnqbu2.fsf@gitster.siamese.dyndns.org>
Junio C Hamano <gitster@pobox.com> wrote:
Show 25 quoted lines
> "Shawn O. Pearce" <spearce@spearce.org> writes:
> 
> > diff --git a/list-objects.c b/list-objects.c
> > index e5c88c2..713bef9 100644
> > --- a/list-objects.c
> > +++ b/list-objects.c
> > @@ -170,4 +170,11 @@ void traverse_commit_list(struct rev_info *revs,
> >  	}
> >  	for (i = 0; i < objects.nr; i++)
> >  		show_object(&objects.objects[i]);
> > +	free(objects.objects);
> > +	if (revs->pending.nr) {
> > +		revs->pending.nr = 0;
> > +		revs->pending.alloc = 0;
> > +		revs->pending.objects = NULL;
> > +		free(revs->pending.objects);
> > +	}
> >  }
> 
> It is locally verifiable that objects.objects are no longer
> needed after this point, but it made me a bit nervous about
> freeing of revs->pending.objects.
> 
> I think the existing callers are all Ok, but somebody else
> should double check.
There are 5 calllers:
* builtin-fetch.c:
   This one I added with my series.  It doesn't care about the
   pending object list.
* builtin-pack-objects.c:
   This doesn't care about the pending list after the call to
   traverse_commit_list.
* builtin-rev-list.c (2):
   Two calls; the first one is for the bisect case where we print
   bisect stats and then return 0 and the second is the end of
   the program for the non-bisect case.  Neither cares about the
   pending list.
* upload-pack.c:
   This is called in the async thread spawned by upload-pack to
   feed pack-objects.  The last thing the async thread does is run
   traverse_commit_list, at which point it exits.  I actually have
   to wonder why we didn't just teach this trick to pack-objects
   so we could avoid the async complexity here in upload-pack.

So yea, the cleanup here is safe, assuming I didn't make the extremely obvious leak of setting to NULL then calling free() (as Dscho pointed out).

-- 
Shawn.
Previous: Johannes Schindelin
Message 4 of 4 in “Fix memory leak in traverse_commit_list”
  1. 01/11 Fix memory leak in traverse_commit_listShawn O. Pearce, Nov 9, 2007
  2. Junio C HamanoNov 9, 2007
  3. Johannes SchindelinNov 9, 2007
  4. Shawn O. PearceNov 11, 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.