Skip to content

Commit c92abe7

Browse files
pks-tgitster
authored andcommitted
builtin/fetch: fix leaking transaction with --atomic
With the `--atomic` flag, we use a single ref transaction to commit all ref updates in git-fetch(1). The lifetime of transactions is somewhat weird: while `ref_transaction_abort()` will free the transaction, a call to `ref_transaction_commit()` won't. We thus have to manually free the transaction in the successful case. Adapt the code to free the transaction in the exit path to plug the resulting memory leak. As `ref_transaction_abort()` already freed the transaction for us, we have to unset the transaction when we hit that code path to not cause a double free. Signed-off-by: Patrick Steinhardt <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 8960819 commit c92abe7

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

builtin/fetch.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1731,11 +1731,8 @@ static int do_fetch(struct transport *transport,
17311731
goto cleanup;
17321732

17331733
retcode = ref_transaction_commit(transaction, &err);
1734-
if (retcode) {
1735-
ref_transaction_free(transaction);
1736-
transaction = NULL;
1734+
if (retcode)
17371735
goto cleanup;
1738-
}
17391736
}
17401737

17411738
commit_fetch_head(&fetch_head);
@@ -1803,8 +1800,11 @@ static int do_fetch(struct transport *transport,
18031800
if (transaction && ref_transaction_abort(transaction, &err) &&
18041801
err.len)
18051802
error("%s", err.buf);
1803+
transaction = NULL;
18061804
}
18071805

1806+
if (transaction)
1807+
ref_transaction_free(transaction);
18081808
display_state_release(&display_state);
18091809
close_fetch_head(&fetch_head);
18101810
strbuf_release(&err);

t/t5574-fetch-output.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ test_description='git fetch output format'
55
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
66
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
77

8+
TEST_PASSES_SANITIZE_LEAK=true
89
. ./test-lib.sh
910

1011
test_expect_success 'fetch with invalid output format configuration' '

0 commit comments

Comments
 (0)