git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] sha1_file: fix delta_stack memory leak in unpack_entry
@ 2014-02-20 23:47 Nguyễn Thái Ngọc Duy
  2014-02-21  5:41 ` Jeff King
  0 siblings, 1 reply; 5+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2014-02-20 23:47 UTC (permalink / raw)
  To: git; +Cc: Nguyễn Thái Ngọc Duy

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(+)

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

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] sha1_file: fix delta_stack memory leak in unpack_entry
  2014-02-20 23:47 [PATCH] sha1_file: fix delta_stack memory leak in unpack_entry Nguyễn Thái Ngọc Duy
@ 2014-02-21  5:41 ` Jeff King
  2014-02-21 18:09   ` Junio C Hamano
  0 siblings, 1 reply; 5+ messages in thread
From: Jeff King @ 2014-02-21  5:41 UTC (permalink / raw)
  To: Nguyễn Thái Ngọc Duy; +Cc: git

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.

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

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] sha1_file: fix delta_stack memory leak in unpack_entry
  2014-02-21  5:41 ` Jeff King
@ 2014-02-21 18:09   ` Junio C Hamano
  2014-02-22  8:12     ` Jeff King
  2014-02-22 15:44     ` Thomas Rast
  0 siblings, 2 replies; 5+ messages in thread
From: Junio C Hamano @ 2014-02-21 18:09 UTC (permalink / raw)
  To: Jeff King; +Cc: Nguyễn Thái Ngọc Duy, git

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.

> 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.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] sha1_file: fix delta_stack memory leak in unpack_entry
  2014-02-21 18:09   ` Junio C Hamano
@ 2014-02-22  8:12     ` Jeff King
  2014-02-22 15:44     ` Thomas Rast
  1 sibling, 0 replies; 5+ messages in thread
From: Jeff King @ 2014-02-22  8:12 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: Nguyễn Thái Ngọc Duy, git

On Fri, Feb 21, 2014 at 10:09:33AM -0800, Junio C Hamano 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.
> [...]
> 
> This comes from abe601bb, right?  The change looks correct to me, too.

Yes, it does.

-Peff

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] sha1_file: fix delta_stack memory leak in unpack_entry
  2014-02-21 18:09   ` Junio C Hamano
  2014-02-22  8:12     ` Jeff King
@ 2014-02-22 15:44     ` Thomas Rast
  1 sibling, 0 replies; 5+ messages in thread
From: Thomas Rast @ 2014-02-22 15:44 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: Jeff King, Nguyễn Thái Ngọc Duy, git

Junio C Hamano <gitster@pobox.com> writes:

> 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

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2014-02-22 15:44 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-02-20 23:47 [PATCH] sha1_file: fix delta_stack memory leak in unpack_entry Nguyễn Thái Ngọc Duy
2014-02-21  5:41 ` Jeff King
2014-02-21 18:09   ` Junio C Hamano
2014-02-22  8:12     ` Jeff King
2014-02-22 15:44     ` Thomas Rast

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).