diff options
author | Patrick Steinhardt <ps@pks.im> | 2024-08-22 11:18:06 +0200 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2024-08-22 18:18:06 +0200 |
commit | c92abe71dfa154d62dc36f1bc7b6c00184c5dbda (patch) | |
tree | 615357973fd5c2151dada1fa0fcf26f2f64bfd7d /builtin/fetch.c | |
parent | remote: fix leaking peer ref when expanding refmap (diff) | |
download | git-c92abe71dfa154d62dc36f1bc7b6c00184c5dbda.tar.xz git-c92abe71dfa154d62dc36f1bc7b6c00184c5dbda.zip |
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 <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'builtin/fetch.c')
-rw-r--r-- | builtin/fetch.c | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/builtin/fetch.c b/builtin/fetch.c index c297569a47..0264483c0e 100644 --- a/builtin/fetch.c +++ b/builtin/fetch.c @@ -1731,11 +1731,8 @@ static int do_fetch(struct transport *transport, 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); @@ -1803,8 +1800,11 @@ cleanup: 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); |