aboutsummaryrefslogtreecommitdiffstats
path: root/builtin/fetch.c
diff options
context:
space:
mode:
authorJustin Tobler <jltobler@gmail.com>2025-03-20 19:44:37 -0500
committerJunio C Hamano <gitster@pobox.com>2025-03-21 03:59:46 -0700
commitb9fadeead74df1f4fa4a4177e478903d63e600f5 (patch)
tree38ce1c6045c2b6da6d82b10c6ecdfb2809058a5b /builtin/fetch.c
parentGit 2.47.2 (diff)
downloadgit-b9fadeead74df1f4fa4a4177e478903d63e600f5.tar.gz
git-b9fadeead74df1f4fa4a4177e478903d63e600f5.zip
builtin/fetch: avoid aborting closed reference transaction
As part of the reference transaction commit phase, the transaction is set to a closed state regardless of whether it was successful of not. Attempting to abort a closed transaction via `ref_transaction_abort()` results in a `BUG()`. In c92abe71df (builtin/fetch: fix leaking transaction with `--atomic`, 2024-08-22), logic to free a transaction after the commit phase is moved to the centralized exit path. In cases where the transaction commit failed, this results in a closed transaction being aborted and signaling a bug. Free the transaction and set it to NULL when the commit fails. This allows the exit path to correctly handle the error without attempting to abort the transaction. Signed-off-by: Justin Tobler <jltobler@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'builtin/fetch.c')
-rw-r--r--builtin/fetch.c9
1 files changed, 8 insertions, 1 deletions
diff --git a/builtin/fetch.c b/builtin/fetch.c
index 80a64d0d26..5fb6d6bcf1 100644
--- a/builtin/fetch.c
+++ b/builtin/fetch.c
@@ -1732,8 +1732,15 @@ static int do_fetch(struct transport *transport,
goto cleanup;
retcode = ref_transaction_commit(transaction, &err);
- if (retcode)
+ if (retcode) {
+ /*
+ * Explicitly handle transaction cleanup to avoid
+ * aborting an already closed transaction.
+ */
+ ref_transaction_free(transaction);
+ transaction = NULL;
goto cleanup;
+ }
}
commit_fetch_head(&fetch_head);