reftable/record: fix memory leak when decoding object records

When decoding records it is customary to reuse a `struct reftable_ref_record` across calls. Thus, it may happen that the record already holds some allocated memory. When decoding ref and log records we handle this by releasing or reallocating held memory. But we fail to do this for object records, which causes us to leak memory. Fix this memory leak by releasing object records before we decode into them. We may eventually want to reuse memory instead to avoid needless reallocations. But for now, let's just plug the leak and be done. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Patrick Steinhardt committed Mar 7, 2024 at 21:35 UTC 1a0359181263029468736aba04565af308be89d0
1 file changed +2
reftable/record.c
+2
@@ -569,6 +569,8 @@ static int reftable_obj_record_decode(void *rec, struct strbuf key,
569 uint64_t last;
570 int j;
571
572 + reftable_obj_record_release(r);
573 +
574 REFTABLE_ALLOC_ARRAY(r->hash_prefix, key.len);
575 memcpy(r->hash_prefix, key.buf, key.len);
576 r->hash_prefix_len = key.len;