Skip to content

Commit c8e752e

Browse files
brandb97gitster
authored andcommitted
reftable/writer: fix memory leak when padded_write() fails
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent d50a5e8 commit c8e752e

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

reftable/writer.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,10 @@ static int padded_write(struct reftable_writer *w, uint8_t *data, size_t len,
5757
return -1;
5858

5959
n = w->write(w->write_arg, zeroed, w->pending_padding);
60-
if (n < 0)
60+
if (n < 0) {
61+
reftable_free(zeroed);
6162
return n;
63+
}
6264

6365
w->pending_padding = 0;
6466
reftable_free(zeroed);

0 commit comments

Comments
 (0)