{"thread":{"id":"15942","subject":"[PATCH] force_object_loose: Fix memory leak","startedAt":"2008-10-18T00:37:31Z","lastAt":"2008-10-18T18:08:07Z","messageCount":3,"participants":["Björn Steinbrink","Nicolas Pitre","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"93328","messageId":"20081018003731.GA17290@atjola.homenet","threadId":"15942","inReplyTo":null,"subject":"[PATCH] force_object_loose: Fix memory leak","fromName":"Björn Steinbrink","fromEmail":"b.steinbrink@gmx.de","sentAt":"2008-10-18T00:37:31Z","receivedAt":"2008-10-18T00:37:31Z","isPatch":true,"sender":{"key":"b.steinbrink@gmx.de","avatar":"https://avatars.githubusercontent.com/u/230962?v=4"},"body":"read_packed_sha1 expectes its caller to free the buffer it returns, which\nforce_object_loose didn't do.\n\nThis leak is eventually triggered by \"git gc\", when it is manually invoked\nor there are too many packs around, making gc totally unusable when there\nare lots of unreachable objects.\n\nSigned-off-by: Björn Steinbrink <B.Steinbrink@gmx.de>\n---\nTested with a somewhat recent clone of linux-2.6.git:\n\ngit clone linux-2.6 test\ncd test\ngit remote rm origin\ngit reset --hard v2.6.16\ngit for-each-ref --format='%(refname)' refs/tags | \\\n\txargs -i git update-ref -d {}\ngit reflog expire --expire=0 --all\ngit repack -Ad\n\nWithout the fix, I killed repack when its memory usage got past 3 _GB_.\nWith the fix, it stays at around 300MB until it starts writing the\nnew pack, then it goes up to about 550MB or so.\n\n sha1_file.c |    6 +++++-\n 1 files changed, 5 insertions(+), 1 deletions(-)\n\ndiff --git a/sha1_file.c b/sha1_file.c\nindex 3fbb082..70bb453 100644\n--- a/sha1_file.c\n+++ b/sha1_file.c\n@@ -2333,6 +2333,7 @@ int force_object_loose(const unsigned char *sha1, time_t mtime)\n \tenum object_type type;\n \tchar hdr[32];\n \tint hdrlen;\n+\tint ret;\n \n \tif (has_loose_object(sha1))\n \t\treturn 0;\n@@ -2340,7 +2341,10 @@ int force_object_loose(const unsigned char *sha1, time_t mtime)\n \tif (!buf)\n \t\treturn error(\"cannot read sha1_file for %s\", sha1_to_hex(sha1));\n \thdrlen = sprintf(hdr, \"%s %lu\", typename(type), len) + 1;\n-\treturn write_loose_object(sha1, hdr, hdrlen, buf, len, mtime);\n+\tret = write_loose_object(sha1, hdr, hdrlen, buf, len, mtime);\n+\tfree(buf);\n+\n+\treturn ret;\n }\n \n int has_pack_index(const unsigned char *sha1)\n-- \n1.6.0.2.541.g46dc1.dirty\n"},{"id":"93330","messageId":"alpine.LFD.2.00.0810172105030.26244@xanadu.home","threadId":"15942","inReplyTo":"20081018003731.GA17290@atjola.homenet","subject":"Re: [PATCH] force_object_loose: Fix memory leak","fromName":"Nicolas Pitre","fromEmail":"nico@cam.org","sentAt":"2008-10-18T01:25:25Z","receivedAt":"2008-10-18T01:25:25Z","isPatch":true,"sender":{"key":"nico@fluxnic.net","avatar":"https://avatars.githubusercontent.com/u/702790?v=4"},"body":"On Sat, 18 Oct 2008, Björn Steinbrink wrote:\n\n> read_packed_sha1 expectes its caller to free the buffer it returns, which\n> force_object_loose didn't do.\n> \n> This leak is eventually triggered by \"git gc\", when it is manually invoked\n> or there are too many packs around, making gc totally unusable when there\n> are lots of unreachable objects.\n> \n> Signed-off-by: Björn Steinbrink <B.Steinbrink@gmx.de>\n\nGood catch.\n\nAcked-by: Nicolas Pitre <nico@cam.org>\n\n\n> ---\n> Tested with a somewhat recent clone of linux-2.6.git:\n> \n> git clone linux-2.6 test\n> cd test\n> git remote rm origin\n> git reset --hard v2.6.16\n> git for-each-ref --format='%(refname)' refs/tags | \\\n> \txargs -i git update-ref -d {}\n> git reflog expire --expire=0 --all\n> git repack -Ad\n> \n> Without the fix, I killed repack when its memory usage got past 3 _GB_.\n> With the fix, it stays at around 300MB until it starts writing the\n> new pack, then it goes up to about 550MB or so.\n> \n>  sha1_file.c |    6 +++++-\n>  1 files changed, 5 insertions(+), 1 deletions(-)\n> \n> diff --git a/sha1_file.c b/sha1_file.c\n> index 3fbb082..70bb453 100644\n> --- a/sha1_file.c\n> +++ b/sha1_file.c\n> @@ -2333,6 +2333,7 @@ int force_object_loose(const unsigned char *sha1, time_t mtime)\n>  \tenum object_type type;\n>  \tchar hdr[32];\n>  \tint hdrlen;\n> +\tint ret;\n>  \n>  \tif (has_loose_object(sha1))\n>  \t\treturn 0;\n> @@ -2340,7 +2341,10 @@ int force_object_loose(const unsigned char *sha1, time_t mtime)\n>  \tif (!buf)\n>  \t\treturn error(\"cannot read sha1_file for %s\", sha1_to_hex(sha1));\n>  \thdrlen = sprintf(hdr, \"%s %lu\", typename(type), len) + 1;\n> -\treturn write_loose_object(sha1, hdr, hdrlen, buf, len, mtime);\n> +\tret = write_loose_object(sha1, hdr, hdrlen, buf, len, mtime);\n> +\tfree(buf);\n> +\n> +\treturn ret;\n>  }\n>  \n>  int has_pack_index(const unsigned char *sha1)\n> -- \n> 1.6.0.2.541.g46dc1.dirty\n> --\n> To unsubscribe from this list: send the line \"unsubscribe git\" in\n> the body of a message to majordomo@vger.kernel.org\n> More majordomo info at  http://vger.kernel.org/majordomo-info.html\n> \n\n\nNicolas\n"},{"id":"93380","messageId":"7v1vyddbeg.fsf@gitster.siamese.dyndns.org","threadId":"15942","inReplyTo":"alpine.LFD.2.00.0810172105030.26244@xanadu.home","subject":"Re: [PATCH] force_object_loose: Fix memory leak","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2008-10-18T18:08:07Z","receivedAt":"2008-10-18T18:08:07Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Thanks.\n"}]}