Skip to content

Commit 936e588

Browse files
committed
Merge branch 'ah/plugleaks'
Plug various leans reported by LSAN. * ah/plugleaks: builtin/rm: avoid leaking pathspec and seen builtin/rebase: release git_format_patch_opt too builtin/for-each-ref: free filter and UNLEAK sorting. mailinfo: also free strbuf lists when clearing mailinfo builtin/checkout: clear pending objects after diffing builtin/check-ignore: clear_pathspec before returning builtin/bugreport: don't leak prefixed filename branch: FREE_AND_NULL instead of NULL'ing real_ref bloom: clear each bloom_key after use ls-files: free max_prefix when done wt-status: fix multiple small leaks revision: free remainder of old commit list in limit_list
2 parents 8585d6c + 37be119 commit 936e588

File tree

13 files changed

+36
-23
lines changed

13 files changed

+36
-23
lines changed

bloom.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,7 @@ struct bloom_filter *get_or_compute_bloom_filter(struct repository *r,
283283
struct bloom_key key;
284284
fill_bloom_key(e->path, strlen(e->path), &key, settings);
285285
add_key_to_filter(&key, filter, settings);
286+
clear_bloom_key(&key);
286287
}
287288

288289
cleanup:

branch.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ void create_branch(struct repository *r,
294294
if (explicit_tracking)
295295
die(_(upstream_not_branch), start_name);
296296
else
297-
real_ref = NULL;
297+
FREE_AND_NULL(real_ref);
298298
}
299299
break;
300300
default:

builtin/bugreport.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ int cmd_bugreport(int argc, const char **argv, const char *prefix)
129129
char *option_output = NULL;
130130
char *option_suffix = "%Y-%m-%d-%H%M";
131131
const char *user_relative_path = NULL;
132+
char *prefixed_filename;
132133

133134
const struct option bugreport_options[] = {
134135
OPT_STRING('o', "output-directory", &option_output, N_("path"),
@@ -142,9 +143,9 @@ int cmd_bugreport(int argc, const char **argv, const char *prefix)
142143
bugreport_usage, 0);
143144

144145
/* Prepare the path to put the result */
145-
strbuf_addstr(&report_path,
146-
prefix_filename(prefix,
147-
option_output ? option_output : ""));
146+
prefixed_filename = prefix_filename(prefix,
147+
option_output ? option_output : "");
148+
strbuf_addstr(&report_path, prefixed_filename);
148149
strbuf_complete(&report_path, '/');
149150

150151
strbuf_addstr(&report_path, "git-bugreport-");
@@ -189,6 +190,7 @@ int cmd_bugreport(int argc, const char **argv, const char *prefix)
189190
fprintf(stderr, _("Created new report at '%s'.\n"),
190191
user_relative_path);
191192

193+
free(prefixed_filename);
192194
UNLEAK(buffer);
193195
UNLEAK(report_path);
194196
return !!launch_editor(report_path.buf, NULL, NULL);

builtin/check-ignore.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ static int check_ignore(struct dir_struct *dir,
119119
num_ignored++;
120120
}
121121
free(seen);
122+
clear_pathspec(&pathspec);
122123

123124
return num_ignored;
124125
}

builtin/checkout.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -607,6 +607,7 @@ static void show_local_changes(struct object *head,
607607
diff_setup_done(&rev.diffopt);
608608
add_pending_object(&rev, head, NULL);
609609
run_diff_index(&rev, 0);
610+
object_array_clear(&rev.pending);
610611
}
611612

612613
static void describe_detached_head(const char *msg, struct commit *commit)

builtin/for-each-ref.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,5 +94,8 @@ int cmd_for_each_ref(int argc, const char **argv, const char *prefix)
9494
strbuf_release(&err);
9595
strbuf_release(&output);
9696
ref_array_clear(&array);
97+
free_commit_list(filter.with_commit);
98+
free_commit_list(filter.no_commit);
99+
UNLEAK(sorting);
97100
return 0;
98101
}

builtin/ls-files.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -607,7 +607,7 @@ static int option_parse_exclude_standard(const struct option *opt,
607607
int cmd_ls_files(int argc, const char **argv, const char *cmd_prefix)
608608
{
609609
int require_work_tree = 0, show_tag = 0, i;
610-
const char *max_prefix;
610+
char *max_prefix;
611611
struct dir_struct dir;
612612
struct pattern_list *pl;
613613
struct string_list exclude_list = STRING_LIST_INIT_NODUP;
@@ -785,5 +785,6 @@ int cmd_ls_files(int argc, const char **argv, const char *cmd_prefix)
785785
}
786786

787787
dir_clear(&dir);
788+
free(max_prefix);
788789
return 0;
789790
}

builtin/rebase.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2109,6 +2109,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
21092109
free(options.head_name);
21102110
free(options.gpg_sign_opt);
21112111
free(options.cmd);
2112+
strbuf_release(&options.git_format_patch_opt);
21122113
free(squash_onto_name);
21132114
return ret;
21142115
}

builtin/rm.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,8 @@ int cmd_rm(int argc, const char **argv, const char *prefix)
342342
if (!seen_any)
343343
exit(ret);
344344
}
345+
clear_pathspec(&pathspec);
346+
free(seen);
345347

346348
if (!index_only)
347349
submodules_absorb_gitdir_if_needed();

mailinfo.c

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -821,7 +821,7 @@ static int handle_commit_msg(struct mailinfo *mi, struct strbuf *line)
821821
for (i = 0; header[i]; i++) {
822822
if (mi->s_hdr_data[i])
823823
strbuf_release(mi->s_hdr_data[i]);
824-
mi->s_hdr_data[i] = NULL;
824+
FREE_AND_NULL(mi->s_hdr_data[i]);
825825
}
826826
return 0;
827827
}
@@ -1236,22 +1236,14 @@ void setup_mailinfo(struct mailinfo *mi)
12361236

12371237
void clear_mailinfo(struct mailinfo *mi)
12381238
{
1239-
int i;
1240-
12411239
strbuf_release(&mi->name);
12421240
strbuf_release(&mi->email);
12431241
strbuf_release(&mi->charset);
12441242
strbuf_release(&mi->inbody_header_accum);
12451243
free(mi->message_id);
12461244

1247-
if (mi->p_hdr_data)
1248-
for (i = 0; mi->p_hdr_data[i]; i++)
1249-
strbuf_release(mi->p_hdr_data[i]);
1250-
free(mi->p_hdr_data);
1251-
if (mi->s_hdr_data)
1252-
for (i = 0; mi->s_hdr_data[i]; i++)
1253-
strbuf_release(mi->s_hdr_data[i]);
1254-
free(mi->s_hdr_data);
1245+
strbuf_list_free(mi->p_hdr_data);
1246+
strbuf_list_free(mi->s_hdr_data);
12551247

12561248
while (mi->content < mi->content_top) {
12571249
free(*(mi->content_top));

revision.c

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1393,20 +1393,20 @@ static int limit_list(struct rev_info *revs)
13931393
{
13941394
int slop = SLOP;
13951395
timestamp_t date = TIME_MAX;
1396-
struct commit_list *list = revs->commits;
1396+
struct commit_list *original_list = revs->commits;
13971397
struct commit_list *newlist = NULL;
13981398
struct commit_list **p = &newlist;
13991399
struct commit_list *bottom = NULL;
14001400
struct commit *interesting_cache = NULL;
14011401

14021402
if (revs->ancestry_path) {
1403-
bottom = collect_bottom_commits(list);
1403+
bottom = collect_bottom_commits(original_list);
14041404
if (!bottom)
14051405
die("--ancestry-path given but there are no bottom commits");
14061406
}
14071407

1408-
while (list) {
1409-
struct commit *commit = pop_commit(&list);
1408+
while (original_list) {
1409+
struct commit *commit = pop_commit(&original_list);
14101410
struct object *obj = &commit->object;
14111411
show_early_output_fn_t show;
14121412

@@ -1415,11 +1415,11 @@ static int limit_list(struct rev_info *revs)
14151415

14161416
if (revs->max_age != -1 && (commit->date < revs->max_age))
14171417
obj->flags |= UNINTERESTING;
1418-
if (process_parents(revs, commit, &list, NULL) < 0)
1418+
if (process_parents(revs, commit, &original_list, NULL) < 0)
14191419
return -1;
14201420
if (obj->flags & UNINTERESTING) {
14211421
mark_parents_uninteresting(commit);
1422-
slop = still_interesting(list, date, slop, &interesting_cache);
1422+
slop = still_interesting(original_list, date, slop, &interesting_cache);
14231423
if (slop)
14241424
continue;
14251425
break;
@@ -1452,14 +1452,17 @@ static int limit_list(struct rev_info *revs)
14521452
* Check if any commits have become TREESAME by some of their parents
14531453
* becoming UNINTERESTING.
14541454
*/
1455-
if (limiting_can_increase_treesame(revs))
1455+
if (limiting_can_increase_treesame(revs)) {
1456+
struct commit_list *list = NULL;
14561457
for (list = newlist; list; list = list->next) {
14571458
struct commit *c = list->item;
14581459
if (c->object.flags & (UNINTERESTING | TREESAME))
14591460
continue;
14601461
update_treesame(revs, c);
14611462
}
1463+
}
14621464

1465+
free_commit_list(original_list);
14631466
revs->commits = newlist;
14641467
return 0;
14651468
}

strbuf.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,8 @@ void strbuf_list_free(struct strbuf **sbs)
209209
{
210210
struct strbuf **s = sbs;
211211

212+
if (!s)
213+
return;
212214
while (*s) {
213215
strbuf_release(*s);
214216
free(*s++);

wt-status.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -616,6 +616,7 @@ static void wt_status_collect_changes_worktree(struct wt_status *s)
616616
rev.diffopt.rename_score = s->rename_score >= 0 ? s->rename_score : rev.diffopt.rename_score;
617617
copy_pathspec(&rev.prune_data, &s->pathspec);
618618
run_diff_files(&rev, 0);
619+
clear_pathspec(&rev.prune_data);
619620
}
620621

621622
static void wt_status_collect_changes_index(struct wt_status *s)
@@ -652,6 +653,8 @@ static void wt_status_collect_changes_index(struct wt_status *s)
652653
rev.diffopt.rename_score = s->rename_score >= 0 ? s->rename_score : rev.diffopt.rename_score;
653654
copy_pathspec(&rev.prune_data, &s->pathspec);
654655
run_diff_index(&rev, 1);
656+
object_array_clear(&rev.pending);
657+
clear_pathspec(&rev.prune_data);
655658
}
656659

657660
static void wt_status_collect_changes_initial(struct wt_status *s)
@@ -2480,6 +2483,7 @@ int has_uncommitted_changes(struct repository *r,
24802483

24812484
diff_setup_done(&rev_info.diffopt);
24822485
result = run_diff_index(&rev_info, 1);
2486+
object_array_clear(&rev_info.pending);
24832487
return diff_result_code(&rev_info.diffopt, result);
24842488
}
24852489

0 commit comments

Comments
 (0)