All of lore.kernel.org
 help / color / mirror / Atom feed
From: Patrick Steinhardt <ps@pks.im>
To: git@vger.kernel.org
Subject: [PATCH v2 1/2] reftable/record: fix memory leak when decoding object records
Date: Thu, 7 Mar 2024 21:35:58 +0100	[thread overview]
Message-ID: <a963054f9a063ca0c4fdcf613fd0ab2e9c681ac9.1709843663.git.ps@pks.im> (raw)
In-Reply-To: <cover.1709843663.git.ps@pks.im>

[-- Attachment #1: Type: text/plain, Size: 1106 bytes --]

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


[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

  reply	other threads:[~2024-03-07 20:36 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-07 15:26 [PATCH] reftable/block: fix binary search over restart counter Patrick Steinhardt
2024-03-07 16:24 ` Patrick Steinhardt
2024-03-07 20:35 ` [PATCH v2 0/2] " Patrick Steinhardt
2024-03-07 20:35   ` Patrick Steinhardt [this message]
2024-03-07 20:36   ` [PATCH v2 2/2] " Patrick Steinhardt
2024-03-07 23:29     ` Junio C Hamano
2024-03-08  0:40       ` Junio C Hamano
2024-03-11  5:18         ` Patrick Steinhardt
2024-03-11 17:33           ` Junio C Hamano

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=a963054f9a063ca0c4fdcf613fd0ab2e9c681ac9.1709843663.git.ps@pks.im \
    --to=ps@pks.im \
    --cc=git@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.