summaryrefslogtreecommitdiff
path: root/refs/files-backend.c
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2019-04-16 10:28:11 (GMT)
committerJunio C Hamano <gitster@pobox.com>2019-04-16 10:28:11 (GMT)
commit2e08c892a7037ce2c7dfe30134eb54a2825bf0be (patch)
treeb2fd76651d0f0bb17e788da15612f4640f30f189 /refs/files-backend.c
parent3feaacbaa15f6437a1767935a5ff04fdef0e86e3 (diff)
parentd3322eb28b142a893fbc03142724bb54e95990a6 (diff)
downloadgit-2e08c892a7037ce2c7dfe30134eb54a2825bf0be.zip
git-2e08c892a7037ce2c7dfe30134eb54a2825bf0be.tar.gz
git-2e08c892a7037ce2c7dfe30134eb54a2825bf0be.tar.bz2
Merge branch 'jk/refs-double-abort'
A corner case bug in the refs API has been corrected. * jk/refs-double-abort: refs/files-backend: don't look at an aborted transaction refs/files-backend: handle packed transaction prepare failure
Diffstat (limited to 'refs/files-backend.c')
-rw-r--r--refs/files-backend.c16
1 files changed, 15 insertions, 1 deletions
diff --git a/refs/files-backend.c b/refs/files-backend.c
index 5848f32..63e55e6 100644
--- a/refs/files-backend.c
+++ b/refs/files-backend.c
@@ -2701,18 +2701,32 @@ static int files_transaction_prepare(struct ref_store *ref_store,
if (is_packed_transaction_needed(refs->packed_ref_store,
packed_transaction)) {
ret = ref_transaction_prepare(packed_transaction, err);
+ /*
+ * A failure during the prepare step will abort
+ * itself, but not free. Do that now, and disconnect
+ * from the files_transaction so it does not try to
+ * abort us when we hit the cleanup code below.
+ */
+ if (ret) {
+ ref_transaction_free(packed_transaction);
+ backend_data->packed_transaction = NULL;
+ }
} else {
/*
* We can skip rewriting the `packed-refs`
* file. But we do need to leave it locked, so
* that somebody else doesn't pack a reference
* that we are trying to delete.
+ *
+ * We need to disconnect our transaction from
+ * backend_data, since the abort (whether successful or
+ * not) will free it.
*/
+ backend_data->packed_transaction = NULL;
if (ref_transaction_abort(packed_transaction, err)) {
ret = TRANSACTION_GENERIC_ERROR;
goto cleanup;
}
- backend_data->packed_transaction = NULL;
}
}