refs/reftable: fix leak when copying reflog fails

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> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Patrick Steinhardt committed Feb 8, 2024 at 06:26 UTC 8a0bebdeaec60623c8a791b197d574bdd031a452
1 file changed +1 -1
refs/reftable-backend.c
+1 -1
@@ -1503,7 +1503,7 @@ static int write_copy_table(struct reftable_writer *writer, void *cb_data)
1503 */
1504 ret = reftable_merged_table_seek_log(mt, &it, arg->oldname);
1505 if (ret < 0)
1506 - return ret;
1506 + goto done;
1507
1508 while (1) {
1509 ret = reftable_iterator_next_log(&it, &old_log);