summaryrefslogtreecommitdiff
path: root/refs
diff options
context:
space:
mode:
authorPatrick Steinhardt <ps@pks.im>2020-03-30 13:46:13 (GMT)
committerJunio C Hamano <gitster@pobox.com>2020-03-30 17:34:11 (GMT)
commitedc30691e5729435177e4fdccb8c13c3948e3c5a (patch)
tree6e12dabd71cf61b62d94ca51619940ce837be913 /refs
parent3bab5d56259722843359702bc27111475437ad2a (diff)
downloadgit-edc30691e5729435177e4fdccb8c13c3948e3c5a.zip
git-edc30691e5729435177e4fdccb8c13c3948e3c5a.tar.gz
git-edc30691e5729435177e4fdccb8c13c3948e3c5a.tar.bz2
refs: fix segfault when aborting empty transaction
When cleaning up a transaction that has no updates queued, then the transaction's backend data will not have been allocated. We correctly handle this for the packed backend, where the cleanup function checks whether the backend data has been allocated at all -- if not, then there is nothing to clean up. For the files backend we do not check this and as a result will hit a segfault due to dereferencing a `NULL` pointer when cleaning up such a transaction. Fix the issue by checking whether `backend_data` is set in the files backend, too. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'refs')
-rw-r--r--refs/files-backend.c18
1 files changed, 10 insertions, 8 deletions
diff --git a/refs/files-backend.c b/refs/files-backend.c
index 561c33a..6516c7b 100644
--- a/refs/files-backend.c
+++ b/refs/files-backend.c
@@ -2565,16 +2565,18 @@ static void files_transaction_cleanup(struct files_ref_store *refs,
}
}
- if (backend_data->packed_transaction &&
- ref_transaction_abort(backend_data->packed_transaction, &err)) {
- error("error aborting transaction: %s", err.buf);
- strbuf_release(&err);
- }
+ if (backend_data) {
+ if (backend_data->packed_transaction &&
+ ref_transaction_abort(backend_data->packed_transaction, &err)) {
+ error("error aborting transaction: %s", err.buf);
+ strbuf_release(&err);
+ }
- if (backend_data->packed_refs_locked)
- packed_refs_unlock(refs->packed_ref_store);
+ if (backend_data->packed_refs_locked)
+ packed_refs_unlock(refs->packed_ref_store);
- free(backend_data);
+ free(backend_data);
+ }
transaction->state = REF_TRANSACTION_CLOSED;
}