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

Re: [PATCH] git cat-file: Fix memory leak in batch mode

From
Björn Steinbrink <b.steinbrink@gmx.de>
Date
Jun 29, 2008, 11:54 UTC
Message-ID
<20080629115417.GA14806@atjola.homenet>
In-Reply-To
<7v1w2gkj3l.fsf@gitster.siamese.dyndns.org>
On 2008.06.28 20:36:46 -0700, Junio C Hamano wrote:
Show 27 quoted lines
> Björn Steinbrink <B.Steinbrink@gmx.de> writes:
> 
> > When run in batch mode, git cat-file never frees the memory for the blob
> > contents it is printing. This quickly adds up and causes git-svn to be
> > hardly usable for imports of large svn repos, because it uses cat-file in
> > batch mode and cat-file's memory usage easily reaches several hundred MB
> > without any good reason.
> >
> > Signed-off-by: Björn Steinbrink <B.Steinbrink@gmx.de>
> > ---
> >  builtin-cat-file.c |    1 +
> >  1 files changed, 1 insertions(+), 0 deletions(-)
> >
> > diff --git a/builtin-cat-file.c b/builtin-cat-file.c
> > index bd343ef..f966dcb 100644
> > --- a/builtin-cat-file.c
> > +++ b/builtin-cat-file.c
> > @@ -183,6 +183,7 @@ static int batch_one_object(const char *obj_name, int print_contents)
> >  		fflush(stdout);
> >  	}
> >  
> > +	free(contents);
> >  	return 0;
> >  }
> 
> Thanks, except that it should go inside the "if (print_contents == BATCH)"
> block to avoid freeing an uninitialized pointer.

Ah crap, I even wondered about the kill-a-warning initialization of "contents", but my brain was already asleep.

Thanks, Björn

Previous: Junio C HamanoNext: Björn Steinbrink
Message 7 of 11 in “git-svn messed up import, badly”
  1. Björn SteinbrinkJun 28, 2008
  2. Revert "git-svn: Speed up fetch"Avery Pennarun, Jun 28, 2008
  3. git-svn: avoid filling up the disk with temp files.Avery Pennarun, Jun 28, 2008
  4. Björn SteinbrinkJun 29, 2008
  5. git cat-file: Fix memory leak in batch modeBjörn Steinbrink, Jun 29, 2008
  6. Junio C HamanoJun 29, 2008
  7. Björn SteinbrinkJun 29, 2008
  8. Björn SteinbrinkJun 29, 2008
  9. Eric WongJun 29, 2008
  10. Mikael MagnussonJun 28, 2008
  11. Avery PennarunJun 28, 2008

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.