threads / patch / 60872

patchrefs/reftable: fix leak when copying reflog fails

Subject: [PATCH] refs/reftable: fix leak when copying reflog fails

## tl;dr

2 messages between Feb 8, 2024 and Feb 15, 2024. Diffs are folded; open one to read it.

replies: 1people: 2as markdown or json

Patrick Steinhardt· Feb 8, 2024, 05:26 UTC · lore

When copying a ref with the reftable backend we also copy the corresponding log records. When seeking the first log record that we're about to copy fails though we directly return from `write_copy_table()` without doing any cleanup, leaking several allocated data structures.

Fix this by exiting via our common cleanup logic instead.
Reported-by: Jeff King <peff@peff.net> via Coverity
Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
 refs/reftable-backend.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Show changes to refs/reftable-backend.c +1 −1
diff --git a/refs/reftable-backend.c b/refs/reftable-backend.c
index 85214baa60..a14f2ad7f4 100644
--- a/refs/reftable-backend.c
+++ b/refs/reftable-backend.c
@@ -1503,7 +1503,7 @@ static int write_copy_table(struct reftable_writer *writer, void *cb_data)
 	 */
 	ret = reftable_merged_table_seek_log(mt, &it, arg->oldname);
 	if (ret < 0)
-		return ret;
+		goto done;
 
 	while (1) {
 		ret = reftable_iterator_next_log(&it, &old_log);
-- 
2.43.GIT
Jeff King· Feb 15, 2024, 05:32 UTC · re: Patrick Steinhardt · lore

Re: [PATCH] refs/reftable: fix leak when copying reflog fails

On Thu, Feb 08, 2024 at 06:26:14AM +0100, Patrick Steinhardt wrote:
Show 6 quoted lines
> When copying a ref with the reftable backend we also copy the
> corresponding log records. When seeking the first log record that we're
> about to copy fails though we directly return from `write_copy_table()`
> without doing any cleanup, leaking several allocated data structures.
> 
> Fix this by exiting via our common cleanup logic instead.
Thanks, this looks obviously correct to me. :)
-Peff

← back to recent threads