Skip to content

Commit 57efebb

Browse files
avargitster
authored andcommitted
bisect.c: partially fix bisect_rev_setup() memory leak
Partially fix the memory leak noted in in 8a534b6 (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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent f89d085 commit 57efebb

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

bisect.c

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -648,28 +648,28 @@ static struct commit_list *managed_skipped(struct commit_list *list,
648648
}
649649

650650
static void bisect_rev_setup(struct repository *r, struct rev_info *revs,
651+
struct strvec *rev_argv,
651652
const char *prefix,
652653
const char *bad_format, const char *good_format,
653654
int read_paths)
654655
{
655-
struct strvec rev_argv = STRVEC_INIT;
656656
int i;
657657

658658
repo_init_revisions(r, revs, prefix);
659659
revs->abbrev = 0;
660660
revs->commit_format = CMIT_FMT_UNSPECIFIED;
661661

662662
/* rev_argv.argv[0] will be ignored by setup_revisions */
663-
strvec_push(&rev_argv, "bisect_rev_setup");
664-
strvec_pushf(&rev_argv, bad_format, oid_to_hex(current_bad_oid));
663+
strvec_push(rev_argv, "bisect_rev_setup");
664+
strvec_pushf(rev_argv, bad_format, oid_to_hex(current_bad_oid));
665665
for (i = 0; i < good_revs.nr; i++)
666-
strvec_pushf(&rev_argv, good_format,
666+
strvec_pushf(rev_argv, good_format,
667667
oid_to_hex(good_revs.oid + i));
668-
strvec_push(&rev_argv, "--");
668+
strvec_push(rev_argv, "--");
669669
if (read_paths)
670-
read_bisect_paths(&rev_argv);
670+
read_bisect_paths(rev_argv);
671671

672-
setup_revisions(rev_argv.nr, rev_argv.v, revs, NULL);
672+
setup_revisions(rev_argv->nr, rev_argv->v, revs, NULL);
673673
/* XXX leak rev_argv, as "revs" may still be pointing to it */
674674
}
675675

@@ -873,10 +873,11 @@ static enum bisect_error check_merge_bases(int rev_nr, struct commit **rev, int
873873
static int check_ancestors(struct repository *r, int rev_nr,
874874
struct commit **rev, const char *prefix)
875875
{
876+
struct strvec rev_argv = STRVEC_INIT;
876877
struct rev_info revs;
877878
int res;
878879

879-
bisect_rev_setup(r, &revs, prefix, "^%s", "%s", 0);
880+
bisect_rev_setup(r, &revs, &rev_argv, prefix, "^%s", "%s", 0);
880881

881882
bisect_common(&revs);
882883
res = (revs.commits != NULL);
@@ -885,6 +886,7 @@ static int check_ancestors(struct repository *r, int rev_nr,
885886
clear_commit_marks_many(rev_nr, rev, ALL_REV_FLAGS);
886887

887888
release_revisions(&revs);
889+
strvec_clear(&rev_argv);
888890
return res;
889891
}
890892

@@ -1010,6 +1012,7 @@ void read_bisect_terms(const char **read_bad, const char **read_good)
10101012
*/
10111013
enum bisect_error bisect_next_all(struct repository *r, const char *prefix)
10121014
{
1015+
struct strvec rev_argv = STRVEC_INIT;
10131016
struct rev_info revs = REV_INFO_INIT;
10141017
struct commit_list *tried;
10151018
int reaches = 0, all = 0, nr, steps;
@@ -1037,7 +1040,7 @@ enum bisect_error bisect_next_all(struct repository *r, const char *prefix)
10371040
if (res)
10381041
goto cleanup;
10391042

1040-
bisect_rev_setup(r, &revs, prefix, "%s", "^%s", 1);
1043+
bisect_rev_setup(r, &revs, &rev_argv, prefix, "%s", "^%s", 1);
10411044

10421045
revs.first_parent_only = !!(bisect_flags & FIND_BISECTION_FIRST_PARENT_ONLY);
10431046
revs.limited = 1;
@@ -1112,6 +1115,7 @@ enum bisect_error bisect_next_all(struct repository *r, const char *prefix)
11121115
res = bisect_checkout(bisect_rev, no_checkout);
11131116
cleanup:
11141117
release_revisions(&revs);
1118+
strvec_clear(&rev_argv);
11151119
return res;
11161120
}
11171121

0 commit comments

Comments
 (0)