git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v2 1/2] reftable/record: fix memory leak when decoding object records

From
Patrick Steinhardt <ps@pks.im>
Date
Mar 7, 2024, 20:35 UTC
Message-ID
<a963054f9a063ca0c4fdcf613fd0ab2e9c681ac9.1709843663.git.ps@pks.im>
In-Reply-To
<cover.1709843663.git.ps@pks.im>

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>
---
 reftable/record.c | 2 ++
 1 file changed, 2 insertions(+)
diff --git a/reftable/record.c b/reftable/record.c
index d6bb42e887..9c31feb35c 100644
--- a/reftable/record.c
+++ b/reftable/record.c
@@ -569,6 +569,8 @@ static int reftable_obj_record_decode(void *rec, struct strbuf key,
 	uint64_t last;
 	int j;
 
+	reftable_obj_record_release(r);
+
 	REFTABLE_ALLOC_ARRAY(r->hash_prefix, key.len);
 	memcpy(r->hash_prefix, key.buf, key.len);
 	r->hash_prefix_len = key.len;
-- 
2.43.1
Previous: Patrick SteinhardtNext: Patrick Steinhardt
Message 4 of 9 in “reftable/block: fix binary search over restart counter”
  1. reftable/block: fix binary search over restart counterPatrick Steinhardt, Mar 7, 2024
  2. Patrick SteinhardtMar 7, 2024
  3. 0/2 reftable/block: fix binary search over restart counterPatrick Steinhardt, Mar 7, 2024
  4. 1/2 reftable/record: fix memory leak when decoding object recordsPatrick Steinhardt, Mar 7, 2024
  5. 2/2 reftable/block: fix binary search over restart counterPatrick Steinhardt, Mar 7, 2024
  6. Junio C HamanoMar 7, 2024
  7. Junio C HamanoMar 8, 2024
  8. Patrick SteinhardtMar 11, 2024
  9. Junio C HamanoMar 11, 2024

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.