From: "Ævar Arnfjörð Bjarmason" <avarab@gmail.com>
To: git@vger.kernel.org
Cc: "Junio C Hamano" <gitster@pobox.com>, "Jeff King" <peff@peff.net>,
"Ævar Arnfjörð Bjarmason" <avarab@gmail.com>
Subject: [PATCH 5/6] bisect.c: partially fix bisect_rev_setup() memory leak
Date: Wed, 13 Jul 2022 15:10:34 +0200 [thread overview]
Message-ID: <patch-5.6-83897fd108a-20220713T130511Z-avarab@gmail.com> (raw)
In-Reply-To: <cover-0.6-00000000000-20220713T130511Z-avarab@gmail.com>
Partially fix the memory leak noted in in 8a534b61241 (bisect: use
argv_array API, 2011-09-13), which added the "XXX" comment seen in the
context. We can partially fix it by having the bisect_rev_setup()
function take a "struct strvec", rather than constructing it.
As the comment notes we need to keep the construct "rev_argv" around
while the "struct rev_info" is around, which as seen in the newly
added "strvec_clear()" calls here we do after "release_revisions()".
This "partially" fixes the memory leak because we're leaking the "--"
added to the "rev_argv" here still, which will be addressed in a
subsequent commit.
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
bisect.c | 22 +++++++++++++---------
1 file changed, 13 insertions(+), 9 deletions(-)
diff --git a/bisect.c b/bisect.c
index 421470bfa59..6afb98be7a1 100644
--- a/bisect.c
+++ b/bisect.c
@@ -648,11 +648,11 @@ static struct commit_list *managed_skipped(struct commit_list *list,
}
static void bisect_rev_setup(struct repository *r, struct rev_info *revs,
+ struct strvec *rev_argv,
const char *prefix,
const char *bad_format, const char *good_format,
int read_paths)
{
- struct strvec rev_argv = STRVEC_INIT;
int i;
repo_init_revisions(r, revs, prefix);
@@ -660,16 +660,16 @@ static void bisect_rev_setup(struct repository *r, struct rev_info *revs,
revs->commit_format = CMIT_FMT_UNSPECIFIED;
/* rev_argv.argv[0] will be ignored by setup_revisions */
- strvec_push(&rev_argv, "bisect_rev_setup");
- strvec_pushf(&rev_argv, bad_format, oid_to_hex(current_bad_oid));
+ strvec_push(rev_argv, "bisect_rev_setup");
+ strvec_pushf(rev_argv, bad_format, oid_to_hex(current_bad_oid));
for (i = 0; i < good_revs.nr; i++)
- strvec_pushf(&rev_argv, good_format,
+ strvec_pushf(rev_argv, good_format,
oid_to_hex(good_revs.oid + i));
- strvec_push(&rev_argv, "--");
+ strvec_push(rev_argv, "--");
if (read_paths)
- read_bisect_paths(&rev_argv);
+ read_bisect_paths(rev_argv);
- setup_revisions(rev_argv.nr, rev_argv.v, revs, NULL);
+ setup_revisions(rev_argv->nr, rev_argv->v, revs, NULL);
/* XXX leak rev_argv, as "revs" may still be pointing to it */
}
@@ -873,10 +873,11 @@ static enum bisect_error check_merge_bases(int rev_nr, struct commit **rev, int
static int check_ancestors(struct repository *r, int rev_nr,
struct commit **rev, const char *prefix)
{
+ struct strvec rev_argv = STRVEC_INIT;
struct rev_info revs;
int res;
- bisect_rev_setup(r, &revs, prefix, "^%s", "%s", 0);
+ bisect_rev_setup(r, &revs, &rev_argv, prefix, "^%s", "%s", 0);
bisect_common(&revs);
res = (revs.commits != NULL);
@@ -885,6 +886,7 @@ static int check_ancestors(struct repository *r, int rev_nr,
clear_commit_marks_many(rev_nr, rev, ALL_REV_FLAGS);
release_revisions(&revs);
+ strvec_clear(&rev_argv);
return res;
}
@@ -1010,6 +1012,7 @@ void read_bisect_terms(const char **read_bad, const char **read_good)
*/
enum bisect_error bisect_next_all(struct repository *r, const char *prefix)
{
+ struct strvec rev_argv = STRVEC_INIT;
struct rev_info revs = REV_INFO_INIT;
struct commit_list *tried;
int reaches = 0, all = 0, nr, steps;
@@ -1037,7 +1040,7 @@ enum bisect_error bisect_next_all(struct repository *r, const char *prefix)
if (res)
goto cleanup;
- bisect_rev_setup(r, &revs, prefix, "%s", "^%s", 1);
+ bisect_rev_setup(r, &revs, &rev_argv, prefix, "%s", "^%s", 1);
revs.first_parent_only = !!(bisect_flags & FIND_BISECTION_FIRST_PARENT_ONLY);
revs.limited = 1;
@@ -1112,6 +1115,7 @@ enum bisect_error bisect_next_all(struct repository *r, const char *prefix)
res = bisect_checkout(bisect_rev, no_checkout);
cleanup:
release_revisions(&revs);
+ strvec_clear(&rev_argv);
return res;
}
--
2.37.0.932.g7b7031e73bc
next prev parent reply other threads:[~2022-07-13 13:11 UTC|newest]
Thread overview: 52+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-07-13 13:10 [PATCH 0/6] revisions API: fix more memory leaks Ævar Arnfjörð Bjarmason
2022-07-13 13:10 ` [PATCH 1/6] bisect.c: add missing "goto" for release_revisions() Ævar Arnfjörð Bjarmason
2022-07-13 13:10 ` [PATCH 2/6] test-fast-rebase helper: use release_revisions() (again) Ævar Arnfjörð Bjarmason
2022-07-13 13:10 ` [PATCH 3/6] log: make the intent of cmd_show()'s "rev.pending" juggling clearer Ævar Arnfjörð Bjarmason
2022-07-18 14:51 ` Jeff King
2022-07-13 13:10 ` [PATCH 4/6] log: fix common "rev.pending" memory leak in "git show" Ævar Arnfjörð Bjarmason
2022-07-18 14:57 ` Jeff King
2022-07-18 15:08 ` Ævar Arnfjörð Bjarmason
2022-07-13 13:10 ` Ævar Arnfjörð Bjarmason [this message]
2022-07-18 15:05 ` [PATCH 5/6] bisect.c: partially fix bisect_rev_setup() memory leak Jeff King
2022-07-13 13:10 ` [PATCH 6/6] revisions API: don't leak memory on argv elements that need free()-ing Ævar Arnfjörð Bjarmason
2022-07-18 15:11 ` Jeff King
2022-07-18 15:13 ` Ævar Arnfjörð Bjarmason
2022-07-18 15:45 ` Jeff King
2022-07-29 7:07 ` Ævar Arnfjörð Bjarmason
2022-07-29 18:03 ` Jeff King
2022-07-29 18:37 ` Jeff King
2022-07-29 18:52 ` Junio C Hamano
2022-07-29 19:04 ` Jeff King
2022-07-18 15:14 ` [PATCH 0/6] revisions API: fix more memory leaks Jeff King
2022-07-29 8:31 ` [PATCH v2 " Ævar Arnfjörð Bjarmason
2022-07-29 8:31 ` [PATCH v2 1/6] bisect.c: add missing "goto" for release_revisions() Ævar Arnfjörð Bjarmason
2022-07-29 8:31 ` [PATCH v2 2/6] test-fast-rebase helper: use release_revisions() (again) Ævar Arnfjörð Bjarmason
2022-07-30 5:22 ` Eric Sunshine
2022-07-29 8:31 ` [PATCH v2 3/6] log: make the intent of cmd_show()'s "rev.pending" juggling clearer Ævar Arnfjörð Bjarmason
2022-07-29 18:44 ` Junio C Hamano
2022-07-29 8:31 ` [PATCH v2 4/6] log: fix common "rev.pending" memory leak in "git show" Ævar Arnfjörð Bjarmason
2022-07-29 18:55 ` Jeff King
2022-07-29 19:07 ` Jeff King
2022-07-29 18:59 ` Jeff King
2022-07-29 8:31 ` [PATCH v2 5/6] bisect.c: partially fix bisect_rev_setup() memory leak Ævar Arnfjörð Bjarmason
2022-07-29 8:31 ` [PATCH v2 6/6] revisions API: don't leak memory on argv elements that need free()-ing Ævar Arnfjörð Bjarmason
2022-07-29 19:00 ` Jeff King
2022-07-29 19:02 ` [PATCH v2 0/6] revisions API: fix more memory leaks Jeff King
2022-08-02 15:33 ` [PATCH v3 " Ævar Arnfjörð Bjarmason
2022-08-02 15:33 ` [PATCH v3 1/6] bisect.c: add missing "goto" for release_revisions() Ævar Arnfjörð Bjarmason
2022-08-03 17:13 ` Junio C Hamano
2022-08-02 15:33 ` [PATCH v3 2/6] test-fast-rebase helper: use release_revisions() (again) Ævar Arnfjörð Bjarmason
2022-08-02 15:33 ` [PATCH v3 3/6] log: fix a memory leak in "git show <revision>..." Ævar Arnfjörð Bjarmason
2022-08-03 17:27 ` Jeff King
2022-08-03 17:29 ` Jeff King
2022-08-03 17:54 ` Junio C Hamano
2022-08-02 15:33 ` [PATCH v3 4/6] log: refactor "rev.pending" code in cmd_show() Ævar Arnfjörð Bjarmason
2022-08-03 17:32 ` Jeff King
2022-08-03 17:59 ` Junio C Hamano
2022-08-04 7:51 ` Ævar Arnfjörð Bjarmason
2022-08-04 15:59 ` Junio C Hamano
2022-08-05 9:01 ` Ævar Arnfjörð Bjarmason
2022-08-02 15:33 ` [PATCH v3 5/6] bisect.c: partially fix bisect_rev_setup() memory leak Ævar Arnfjörð Bjarmason
2022-08-02 15:33 ` [PATCH v3 6/6] revisions API: don't leak memory on argv elements that need free()-ing Ævar Arnfjörð Bjarmason
2022-08-03 18:30 ` Junio C Hamano
2022-08-03 17:33 ` [PATCH v3 0/6] revisions API: fix more memory leaks Jeff King
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
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=patch-5.6-83897fd108a-20220713T130511Z-avarab@gmail.com \
--to=avarab@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.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.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
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 read-only IMAP folder(s) and NNTP newsgroup(s).