]> git.ipfire.org Git - thirdparty/git.git/commitdiff
reftable/writer: fix memory leak when `padded_write()` fails
authorLidong Yan <502024330056@smail.nju.edu.cn>
Mon, 12 May 2025 12:49:03 +0000 (12:49 +0000)
committerJunio C Hamano <gitster@pobox.com>
Mon, 12 May 2025 16:19:49 +0000 (09:19 -0700)
In reftable/writer.c:padded_write(), if w->writer failed, zeroed
allocated in `reftable_calloc` will leak. w->writer could be
`reftable_write_data` in reftable/stack.c, and could fail due to
some write error. Simply add reftable_free(zeroed) will solve this
problem.

Signed-off-by: Lidong Yan <502024330056@smail.nju.edu.cn>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
reftable/writer.c

index f3ab1035d61d96f5234a2bbaef4f8f0341255ecb..d71a56e8fc4f27abb95a3793b4c9cd746051bde9 100644 (file)
@@ -57,8 +57,10 @@ static int padded_write(struct reftable_writer *w, uint8_t *data, size_t len,
                        return -1;
 
                n = w->write(w->write_arg, zeroed, w->pending_padding);
-               if (n < 0)
+               if (n < 0) {
+                       reftable_free(zeroed);
                        return n;
+               }
 
                w->pending_padding = 0;
                reftable_free(zeroed);