From: "Ævar Arnfjörð Bjarmason" <avarab@gmail.com>
To: git@vger.kernel.org
Cc: "Junio C Hamano" <gitster@pobox.com>,
"Elijah Newren" <newren@gmail.com>,
"Martin Ågren" <martin.agren@gmail.com>,
"Andrzej Hunt" <ajrhunt@google.com>, "Jeff King" <peff@peff.net>,
"Ævar Arnfjörð Bjarmason" <avarab@gmail.com>
Subject: [PATCH v3 3/3] sequencer: fix a memory leak in do_reset()
Date: Wed, 13 Oct 2021 15:23:55 +0200 [thread overview]
Message-ID: <patch-v3-3.3-00b6b469a8c-20211013T132223Z-avarab@gmail.com> (raw)
In-Reply-To: <cover-v3-0.3-00000000000-20211013T132223Z-avarab@gmail.com>
Fix a memory leak introduced in 9055e401dd6 (sequencer: introduce new
commands to reset the revision, 2018-04-25), which called
setup_unpack_trees_porcelain() without a corresponding call to
clear_unpack_trees_porcelain().
This introduces a change in behavior in that we now start calling
clear_unpack_trees_porcelain() even without having called the
setup_unpack_trees_porcelain(). That's OK, that clear function, like
most others, will accept a zero'd out struct.
This inches us closer to passing various tests in
"t34*.sh" (e.g. "t3434-rebase-i18n.sh"), but because they have so many
other memory leaks in revisions.c this doesn't make any test file or
even a single test pass.
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
sequencer.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/sequencer.c b/sequencer.c
index 14c37c4e25b..98181b3186e 100644
--- a/sequencer.c
+++ b/sequencer.c
@@ -3646,7 +3646,7 @@ static int do_reset(struct repository *r,
struct lock_file lock = LOCK_INIT;
struct tree_desc desc = { 0 };
struct tree *tree;
- struct unpack_trees_options unpack_tree_opts;
+ struct unpack_trees_options unpack_tree_opts = { 0 };
int ret = 0;
if (repo_hold_locked_index(r, &lock, LOCK_REPORT_ON_ERROR) < 0)
@@ -3683,7 +3683,6 @@ static int do_reset(struct repository *r,
}
}
- memset(&unpack_tree_opts, 0, sizeof(unpack_tree_opts));
setup_unpack_trees_porcelain(&unpack_tree_opts, "reset");
unpack_tree_opts.head_idx = 1;
unpack_tree_opts.src_index = r->index;
@@ -3724,6 +3723,7 @@ static int do_reset(struct repository *r,
if (ret < 0)
rollback_lock_file(&lock);
strbuf_release(&ref_name);
+ clear_unpack_trees_porcelain(&unpack_tree_opts);
return ret;
}
--
2.33.0.1569.gd2dc77f7abf
prev parent reply other threads:[~2021-10-13 13:24 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-10-06 9:40 [PATCH 0/2] dir & unpak-trees: memory-leak fixes Ævar Arnfjörð Bjarmason
2021-10-06 9:40 ` [PATCH 1/2] unpack-trees: don't leak memory in verify_clean_subdirectory() Ævar Arnfjörð Bjarmason
2021-10-06 15:58 ` Elijah Newren
2021-10-06 9:40 ` [PATCH 2/2] built-ins & lib: plug memory leaks with unpack_trees_options_release() Ævar Arnfjörð Bjarmason
2021-10-06 16:12 ` Elijah Newren
2021-10-06 16:33 ` [PATCH 0/2] dir & unpak-trees: memory-leak fixes Elijah Newren
2021-10-07 9:46 ` [PATCH v2 0/3] unpack-trees: " Ævar Arnfjörð Bjarmason
2021-10-07 9:46 ` [PATCH v2 1/3] unpack-trees: don't leak memory in verify_clean_subdirectory() Ævar Arnfjörð Bjarmason
2021-10-07 22:27 ` Junio C Hamano
2021-10-07 9:46 ` [PATCH v2 2/3] sequencer: add a "goto cleanup" to do_reset() Ævar Arnfjörð Bjarmason
2021-10-07 16:06 ` Elijah Newren
2021-10-07 9:46 ` [PATCH v2 3/3] sequencer: fix a memory leak in do_reset() Ævar Arnfjörð Bjarmason
2021-10-07 16:10 ` [PATCH v2 0/3] unpack-trees: memory-leak fixes Elijah Newren
2021-10-13 13:23 ` [PATCH v3 " Ævar Arnfjörð Bjarmason
2021-10-13 13:23 ` [PATCH v3 1/3] unpack-trees: don't leak memory in verify_clean_subdirectory() Ævar Arnfjörð Bjarmason
2021-10-13 13:23 ` [PATCH v3 2/3] sequencer: add a "goto cleanup" to do_reset() Ævar Arnfjörð Bjarmason
2021-10-13 13:23 ` Ævar Arnfjörð Bjarmason [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=patch-v3-3.3-00b6b469a8c-20211013T132223Z-avarab@gmail.com \
--to=avarab@gmail.com \
--cc=ajrhunt@google.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=martin.agren@gmail.com \
--cc=newren@gmail.com \
--cc=peff@peff.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).