Skip to content

Commit

Permalink
force_object_loose: Fix memory leak
Browse files Browse the repository at this point in the history
read_packed_sha1 expectes its caller to free the buffer it returns, which
force_object_loose didn't do.

This leak is eventually triggered by "git gc", when it is manually invoked
or there are too many packs around, making gc totally unusable when there
are lots of unreachable objects.

Signed-off-by: Björn Steinbrink <B.Steinbrink@gmx.de>
Acked-by: Nicolas Pitre <nico@cam.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
Björn Steinbrink authored and Junio C Hamano committed Oct 18, 2008
1 parent 7213080 commit 1fb23e6
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion sha1_file.c
Original file line number Diff line number Diff line change
Expand Up @@ -2322,14 +2322,18 @@ int force_object_loose(const unsigned char *sha1, time_t mtime)
enum object_type type;
char hdr[32];
int hdrlen;
int ret;

if (has_loose_object(sha1))
return 0;
buf = read_packed_sha1(sha1, &type, &len);
if (!buf)
return error("cannot read sha1_file for %s", sha1_to_hex(sha1));
hdrlen = sprintf(hdr, "%s %lu", typename(type), len) + 1;
return write_loose_object(sha1, hdr, hdrlen, buf, len, mtime);
ret = write_loose_object(sha1, hdr, hdrlen, buf, len, mtime);
free(buf);

return ret;
}

int has_pack_index(const unsigned char *sha1)
Expand Down

0 comments on commit 1fb23e6

Please sign in to comment.