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 <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
goto cleanup;
retcode = ref_transaction_commit(transaction, &err);
- if (retcode) {
- ref_transaction_free(transaction);
- transaction = NULL;
+ if (retcode)
goto cleanup;
- }
}
commit_fetch_head(&fetch_head);
if (transaction && ref_transaction_abort(transaction, &err) &&
err.len)
error("%s", err.buf);
+ transaction = NULL;
}
+ if (transaction)
+ ref_transaction_free(transaction);
display_state_release(&display_state);
close_fetch_head(&fetch_head);
strbuf_release(&err);
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
+TEST_PASSES_SANITIZE_LEAK=true
. ./test-lib.sh
test_expect_success 'fetch with invalid output format configuration' '