Skip to content

Commit 2da81d1

Browse files
committed
Merge branch 'ab/plug-leak-in-revisions'
Plug the memory leaks from the trickiest API of all, the revision walker. * ab/plug-leak-in-revisions: (27 commits) revisions API: add a TODO for diff_free(&revs->diffopt) revisions API: have release_revisions() release "topo_walk_info" revisions API: have release_revisions() release "date_mode" revisions API: call diff_free(&revs->pruning) in revisions_release() revisions API: release "reflog_info" in release revisions() revisions API: clear "boundary_commits" in release_revisions() revisions API: have release_revisions() release "prune_data" revisions API: have release_revisions() release "grep_filter" revisions API: have release_revisions() release "filter" revisions API: have release_revisions() release "cmdline" revisions API: have release_revisions() release "mailmap" revisions API: have release_revisions() release "commits" revisions API users: use release_revisions() for "prune_data" users revisions API users: use release_revisions() with UNLEAK() revisions API users: use release_revisions() in builtin/log.c revisions API users: use release_revisions() in http-push.c revisions API users: add "goto cleanup" for release_revisions() stash: always have the owner of "stash_info" free it revisions API users: use release_revisions() needing REV_INFO_INIT revision.[ch]: document and move code declared around "init" ...
2 parents f31b624 + 54c8a7c commit 2da81d1

File tree

117 files changed

+500
-190
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

117 files changed

+500
-190
lines changed

add-interactive.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -568,8 +568,7 @@ static int get_modified_files(struct repository *r,
568568
run_diff_files(&rev, 0);
569569
}
570570

571-
if (ps)
572-
clear_pathspec(&rev.prune_data);
571+
release_revisions(&rev);
573572
}
574573
hashmap_clear_and_free(&s.file_map, struct pathname_entry, ent);
575574
if (unmerged_count)

bisect.c

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -884,6 +884,7 @@ static int check_ancestors(struct repository *r, int rev_nr,
884884
/* Clean up objects used, as they will be reused. */
885885
clear_commit_marks_many(rev_nr, rev, ALL_REV_FLAGS);
886886

887+
release_revisions(&revs);
887888
return res;
888889
}
889890

@@ -964,6 +965,7 @@ static void show_diff_tree(struct repository *r,
964965

965966
setup_revisions(ARRAY_SIZE(argv) - 1, argv, &opt, NULL);
966967
log_tree_commit(&opt, commit);
968+
release_revisions(&opt);
967969
}
968970

969971
/*
@@ -1008,7 +1010,7 @@ void read_bisect_terms(const char **read_bad, const char **read_good)
10081010
*/
10091011
enum bisect_error bisect_next_all(struct repository *r, const char *prefix)
10101012
{
1011-
struct rev_info revs;
1013+
struct rev_info revs = REV_INFO_INIT;
10121014
struct commit_list *tried;
10131015
int reaches = 0, all = 0, nr, steps;
10141016
enum bisect_error res = BISECT_OK;
@@ -1033,7 +1035,7 @@ enum bisect_error bisect_next_all(struct repository *r, const char *prefix)
10331035

10341036
res = check_good_are_ancestors_of_bad(r, prefix, no_checkout);
10351037
if (res)
1036-
return res;
1038+
goto cleanup;
10371039

10381040
bisect_rev_setup(r, &revs, prefix, "%s", "^%s", 1);
10391041

@@ -1058,14 +1060,16 @@ enum bisect_error bisect_next_all(struct repository *r, const char *prefix)
10581060
term_good,
10591061
term_bad);
10601062

1061-
return BISECT_FAILED;
1063+
res = BISECT_FAILED;
1064+
goto cleanup;
10621065
}
10631066

10641067
if (!all) {
10651068
fprintf(stderr, _("No testable commit found.\n"
10661069
"Maybe you started with bad path arguments?\n"));
10671070

1068-
return BISECT_NO_TESTABLE_COMMIT;
1071+
res = BISECT_NO_TESTABLE_COMMIT;
1072+
goto cleanup;
10691073
}
10701074

10711075
bisect_rev = &revs.commits->item->object.oid;
@@ -1085,7 +1089,8 @@ enum bisect_error bisect_next_all(struct repository *r, const char *prefix)
10851089
* for negative return values for early returns up
10861090
* until the cmd_bisect__helper() caller.
10871091
*/
1088-
return BISECT_INTERNAL_SUCCESS_1ST_BAD_FOUND;
1092+
res = BISECT_INTERNAL_SUCCESS_1ST_BAD_FOUND;
1093+
goto cleanup;
10891094
}
10901095

10911096
nr = all - reaches - 1;
@@ -1104,7 +1109,10 @@ enum bisect_error bisect_next_all(struct repository *r, const char *prefix)
11041109
/* Clean up objects used, as they will be reused. */
11051110
repo_clear_commit_marks(r, ALL_REV_FLAGS);
11061111

1107-
return bisect_checkout(bisect_rev, no_checkout);
1112+
res = bisect_checkout(bisect_rev, no_checkout);
1113+
cleanup:
1114+
release_revisions(&revs);
1115+
return res;
11081116
}
11091117

11101118
static inline int log2i(int n)

builtin/add.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ int add_files_to_cache(const char *prefix,
151151
run_diff_files(&rev, DIFF_RACY_IS_MODIFIED);
152152
end_odb_transaction();
153153

154-
clear_pathspec(&rev.prune_data);
154+
release_revisions(&rev);
155155
return !!data.add_errors;
156156
}
157157

@@ -344,6 +344,7 @@ static int edit_patch(int argc, const char **argv, const char *prefix)
344344

345345
unlink(file);
346346
free(file);
347+
release_revisions(&rev);
347348
return 0;
348349
}
349350

builtin/am.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1397,6 +1397,7 @@ static void write_commit_patch(const struct am_state *state, struct commit *comm
13971397
add_pending_object(&rev_info, &commit->object, "");
13981398
diff_setup_done(&rev_info.diffopt);
13991399
log_tree_commit(&rev_info, commit);
1400+
release_revisions(&rev_info);
14001401
}
14011402

14021403
/**
@@ -1429,6 +1430,7 @@ static void write_index_patch(const struct am_state *state)
14291430
add_pending_object(&rev_info, &tree->object, "");
14301431
diff_setup_done(&rev_info.diffopt);
14311432
run_diff_index(&rev_info, 1);
1433+
release_revisions(&rev_info);
14321434
}
14331435

14341436
/**
@@ -1582,6 +1584,7 @@ static int fall_back_threeway(const struct am_state *state, const char *index_pa
15821584
add_pending_oid(&rev_info, "HEAD", &our_tree, 0);
15831585
diff_setup_done(&rev_info.diffopt);
15841586
run_diff_index(&rev_info, 1);
1587+
release_revisions(&rev_info);
15851588
}
15861589

15871590
if (run_apply(state, index_path))

builtin/bisect--helper.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -596,6 +596,7 @@ static int bisect_skipped_commits(struct bisect_terms *terms)
596596
reset_revision_walk();
597597

598598
strbuf_release(&commit_name);
599+
release_revisions(&revs);
599600
fclose(fp);
600601
return 0;
601602
}
@@ -1084,6 +1085,7 @@ static enum bisect_error bisect_skip(struct bisect_terms *terms, const char **ar
10841085
oid_to_hex(&commit->object.oid));
10851086

10861087
reset_revision_walk();
1088+
release_revisions(&revs);
10871089
} else {
10881090
strvec_push(&argv_state, argv[i]);
10891091
}

builtin/blame.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1171,7 +1171,7 @@ int cmd_blame(int argc, const char **argv, const char *prefix)
11711171
if (!incremental)
11721172
setup_pager();
11731173
else
1174-
return 0;
1174+
goto cleanup;
11751175

11761176
blame_sort_final(&sb);
11771177

@@ -1205,6 +1205,8 @@ int cmd_blame(int argc, const char **argv, const char *prefix)
12051205
printf("num commits: %d\n", sb.num_commits);
12061206
}
12071207

1208+
cleanup:
12081209
cleanup_scoreboard(&sb);
1210+
release_revisions(&revs);
12091211
return 0;
12101212
}

builtin/checkout.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -629,7 +629,7 @@ static void show_local_changes(struct object *head,
629629
diff_setup_done(&rev.diffopt);
630630
add_pending_object(&rev, head, NULL);
631631
run_diff_index(&rev, 0);
632-
object_array_clear(&rev.pending);
632+
release_revisions(&rev);
633633
}
634634

635635
static void describe_detached_head(const char *msg, struct commit *commit)
@@ -1082,6 +1082,7 @@ static void orphaned_commit_warning(struct commit *old_commit, struct commit *ne
10821082

10831083
/* Clean up objects used, as they will be reused. */
10841084
repo_clear_commit_marks(the_repository, ALL_REV_FLAGS);
1085+
release_revisions(&revs);
10851086
}
10861087

10871088
static int switch_branches(const struct checkout_opts *opts,

builtin/commit.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1100,7 +1100,6 @@ static const char *find_author_by_nickname(const char *name)
11001100
struct rev_info revs;
11011101
struct commit *commit;
11021102
struct strbuf buf = STRBUF_INIT;
1103-
struct string_list mailmap = STRING_LIST_INIT_NODUP;
11041103
const char *av[20];
11051104
int ac = 0;
11061105

@@ -1111,7 +1110,8 @@ static const char *find_author_by_nickname(const char *name)
11111110
av[++ac] = buf.buf;
11121111
av[++ac] = NULL;
11131112
setup_revisions(ac, av, &revs, NULL);
1114-
revs.mailmap = &mailmap;
1113+
revs.mailmap = xmalloc(sizeof(struct string_list));
1114+
string_list_init_nodup(revs.mailmap);
11151115
read_mailmap(revs.mailmap);
11161116

11171117
if (prepare_revision_walk(&revs))
@@ -1122,7 +1122,7 @@ static const char *find_author_by_nickname(const char *name)
11221122
ctx.date_mode.type = DATE_NORMAL;
11231123
strbuf_release(&buf);
11241124
format_commit_message(commit, "%aN <%aE>", &buf, &ctx);
1125-
clear_mailmap(&mailmap);
1125+
release_revisions(&revs);
11261126
return strbuf_detach(&buf, NULL);
11271127
}
11281128
die(_("--author '%s' is not 'Name <email>' and matches no existing author"), name);

builtin/describe.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -517,6 +517,7 @@ static void describe_blob(struct object_id oid, struct strbuf *dst)
517517

518518
traverse_commit_list(&revs, process_commit, process_object, &pcd);
519519
reset_revision_walk();
520+
release_revisions(&revs);
520521
}
521522

522523
static void describe(const char *arg, int last_one)
@@ -667,6 +668,7 @@ int cmd_describe(int argc, const char **argv, const char *prefix)
667668
suffix = NULL;
668669
else
669670
suffix = dirty;
671+
release_revisions(&revs);
670672
}
671673
describe("HEAD", 1);
672674
} else if (dirty) {

builtin/diff-files.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,12 @@ int cmd_diff_files(int argc, const char **argv, const char *prefix)
7777

7878
if (read_cache_preload(&rev.diffopt.pathspec) < 0) {
7979
perror("read_cache_preload");
80-
return -1;
80+
result = -1;
81+
goto cleanup;
8182
}
83+
cleanup:
8284
result = run_diff_files(&rev, options);
83-
return diff_result_code(&rev.diffopt, result);
85+
result = diff_result_code(&rev.diffopt, result);
86+
release_revisions(&rev);
87+
return result;
8488
}

0 commit comments

Comments
 (0)