sha1_file: release fallback base's memory in unpack_entry()
If a pack entry that's used as a delta base is corrupt, unpack_entry() marks it as unusable and then searches the object again in the hope that it can be found in another pack or in a loose file. The memory for this external base object is never released. Free it after use. Signed-off-by: Rene Scharfe <l.s.r@web.de> Reviewed-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
René Scharfe committed
Feb 25, 2017 at 11:02 UTC
886ddf4777d119f0a420bdf55fba834c16c58069
1 file changed
+4
sha1_file.c
+4
@@ -2351,6 +2351,7 @@ void *unpack_entry(struct packed_git *p, off_t obj_offset,
2351
while (delta_stack_nr) {
2352
void *delta_data;
2353
void *base = data;
2354
+ void *external_base = NULL;
2355
unsigned long delta_size, base_size = size;
2356
int i;
2357
@@ -2377,6 +2378,7 @@ void *unpack_entry(struct packed_git *p, off_t obj_offset,
2378
p->pack_name);
2379
mark_bad_packed_object(p, base_sha1);
2380
base = read_object(base_sha1, &type, &base_size);
2381
+ external_base = base;
2382
}
2383
}
2384
@@ -2395,6 +2397,7 @@ void *unpack_entry(struct packed_git *p, off_t obj_offset,
2397
"at offset %"PRIuMAX" from %s",
2398
(uintmax_t)curpos, p->pack_name);
2399
data = NULL;
2400
+ free(external_base);
2401
continue;
2402
}
2403
@@ -2414,6 +2417,7 @@ void *unpack_entry(struct packed_git *p, off_t obj_offset,
2417
error("failed to apply delta");
2418
2419
free(delta_data);
2420
+ free(external_base);
2421
}
2422
2423
*final_type = type;