threads / patch / 35922

patchsha1_file: fix delta_stack memory leak in unpack_entry

Subject: [PATCH] sha1_file: fix delta_stack memory leak in unpack_entry

## tl;dr

5 messages between Feb 20, 2014 and Feb 22, 2014. Diffs are folded; open one to read it.

replies: 4people: 4as markdown or json

Nguyễn Thái Ngọc Duy· Feb 20, 2014, 23:47 UTC · lore

This delta_stack array can grow to any length depending on the actual delta chain, but we forget to free it. Normally it does not matter because we use small_delta_stack[] from stack and small_delta_stack can hold 64-delta chains, more than standard --depth=50 in pack-objects.

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 Found when trying to see if making some objects loose at this phase
 could help git-blame and how many objects will be loosened. Gotta go
 soon, didn't really test it, but I bet it'll work.
 sha1_file.c | 4 ++++
 1 file changed, 4 insertions(+)
Show changes to sha1_file.c +4 −0
diff --git a/sha1_file.c b/sha1_file.c
index 6e8c05d..57ab15d 100644
--- a/sha1_file.c
+++ b/sha1_file.c
@@ -2289,6 +2289,10 @@ void *unpack_entry(struct packed_git *p, off_t obj_offset,
 	*final_size = size;
 
 	unuse_pack(&w_curs);
+
+	if (delta_stack != small_delta_stack)
+		free(delta_stack);
+
 	return data;
 }
 
-- 
1.9.0.40.gaa8c3ea
Jeff King· Feb 21, 2014, 05:41 UTC · re: Nguyễn Thái Ngọc Duy · lore

Re: [PATCH] sha1_file: fix delta_stack memory leak in unpack_entry

On Fri, Feb 21, 2014 at 06:47:47AM +0700, Nguyễn Thái Ngọc Duy wrote:
Show 10 quoted lines
> This delta_stack array can grow to any length depending on the actual
> delta chain, but we forget to free it. Normally it does not matter
> because we use small_delta_stack[] from stack and small_delta_stack
> can hold 64-delta chains, more than standard --depth=50 in pack-objects.
> 
> Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
> ---
>  Found when trying to see if making some objects loose at this phase
>  could help git-blame and how many objects will be loosened. Gotta go
>  soon, didn't really test it, but I bet it'll work.
This looks correct to me.

For fun, I measured "git fsck" on linux.git via massif. The peak memory usage dropped from 368MB to 306MB. That's probably an extreme case because it's a big repo and was packed with "--aggressive", but it's still a nice improvement.

-Peff
Junio C Hamano· Feb 21, 2014, 18:09 UTC · re: Jeff King · lore

Re: [PATCH] sha1_file: fix delta_stack memory leak in unpack_entry

Jeff King <peff@peff.net> writes:
Show 14 quoted lines
> On Fri, Feb 21, 2014 at 06:47:47AM +0700, Nguyễn Thái Ngọc Duy wrote:
>
>> This delta_stack array can grow to any length depending on the actual
>> delta chain, but we forget to free it. Normally it does not matter
>> because we use small_delta_stack[] from stack and small_delta_stack
>> can hold 64-delta chains, more than standard --depth=50 in pack-objects.
>> 
>> Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
>> ---
>>  Found when trying to see if making some objects loose at this phase
>>  could help git-blame and how many objects will be loosened. Gotta go
>>  soon, didn't really test it, but I bet it'll work.
>
> This looks correct to me.
This comes from abe601bb, right?  The change looks correct to me, too.
> For fun, I measured "git fsck" on linux.git via massif. The peak memory
> usage dropped from 368MB to 306MB. That's probably an extreme case
> because it's a big repo and was packed with "--aggressive", but it's
> still a nice improvement.
Thanks.
Jeff King· Feb 22, 2014, 08:12 UTC · re: Junio C Hamano · lore

Re: [PATCH] sha1_file: fix delta_stack memory leak in unpack_entry

On Fri, Feb 21, 2014 at 10:09:33AM -0800, Junio C Hamano wrote:
Show 7 quoted lines
> >> This delta_stack array can grow to any length depending on the actual
> >> delta chain, but we forget to free it. Normally it does not matter
> >> because we use small_delta_stack[] from stack and small_delta_stack
> >> can hold 64-delta chains, more than standard --depth=50 in pack-objects.
> [...]
> 
> This comes from abe601bb, right?  The change looks correct to me, too.
Yes, it does.
-Peff
Thomas Rast· Feb 22, 2014, 15:44 UTC · re: Junio C Hamano · lore

Re: [PATCH] sha1_file: fix delta_stack memory leak in unpack_entry

Junio C Hamano <gitster@pobox.com> writes:
Show 18 quoted lines
> Jeff King <peff@peff.net> writes:
>
>> On Fri, Feb 21, 2014 at 06:47:47AM +0700, Nguyễn Thái Ngọc Duy wrote:
>>
>>> This delta_stack array can grow to any length depending on the actual
>>> delta chain, but we forget to free it. Normally it does not matter
>>> because we use small_delta_stack[] from stack and small_delta_stack
>>> can hold 64-delta chains, more than standard --depth=50 in pack-objects.
>>> 
>>> Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
>>> ---
>>>  Found when trying to see if making some objects loose at this phase
>>>  could help git-blame and how many objects will be loosened. Gotta go
>>>  soon, didn't really test it, but I bet it'll work.
>>
>> This looks correct to me.
>
> This comes from abe601bb, right?  The change looks correct to me, too.
Ow, sorry about that.  Thanks for the fix!
-- 
Thomas Rast
tr@thomasrast.ch

← back to recent threads