@matheusbsbs / matheus-bagliano / commits / 1fb23e6550
Fork 0

force_object_loose: Fix memory leak

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>

Björn Steinbrink committed Oct 18, 2008 at 02:37 UTC 1fb23e65503b4927fa1d4b59f9fbe27668ce347d
1 file changed +5 -1
sha1_file.c
+5 -1
@@ -2322,6 +2322,7 @@ int force_object_loose(const unsigned char *sha1, time_t mtime)
2322 enum object_type type;
2323 char hdr[32];
2324 int hdrlen;
2325 + int ret;
2326
2327 if (has_loose_object(sha1))
2328 return 0;
@@ -2329,7 +2330,10 @@ int force_object_loose(const unsigned char *sha1, time_t mtime)
2330 if (!buf)
2331 return error("cannot read sha1_file for %s", sha1_to_hex(sha1));
2332 hdrlen = sprintf(hdr, "%s %lu", typename(type), len) + 1;
2332 - return write_loose_object(sha1, hdr, hdrlen, buf, len, mtime);
2333 + ret = write_loose_object(sha1, hdr, hdrlen, buf, len, mtime);
2334 + free(buf);
2335 +
2336 + return ret;
2337 }
2338
2339 int has_pack_index(const unsigned char *sha1)