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));

0 commit comments

Comments
 (0)