[patch] git: fix memory leak in write-tree.c
- From
- Ingo Molnar <mingo@elte.hu>
- Date
- Apr 14, 2005, 13:12 UTC
- Message-ID
- <20050414131232.GA21543@elte.hu>
- In-Reply-To
- <20050414120834.GA14290@elte.hu>
this patch fixes a memory leak in write-tree.c's write_tree() function - we didnt free the temporary output buffer. Depending on the size of the tree written out this could leak a significant amount of RAM.
Ingo
Signed-off-by: Ingo Molnar <mingo@elte.hu>
--- write-tree.c.orig +++ write-tree.c
@@ -33,12 +33,12 @@ static int write_tree(struct cache_entry { unsigned char subdir_sha1[20]; unsigned long size, offset; - char *buffer; + char *buffer0, *buffer; int i, nr; /* Guess at some random initial size */ size = 8192; - buffer = malloc(size); + buffer0 = buffer = malloc(size); offset = ORIG_OFFSET; nr = 0; @@ -97,6 +97,8 @@ static int write_tree(struct cache_entry offset -= i; write_sha1_file(buffer, offset, returnsha1); + free(buffer0); + return nr; }