Skip to content

Commit cc0b05a

Browse files
matvoregitster
authored andcommitted
list-objects-filter-options: do not over-strbuf_init
The function gently_parse_list_objects_filter is either called with errbuf=STRBUF_INIT or errbuf=NULL, but that function calls strbuf_init when errbuf is not NULL. strbuf_init is only necessary if errbuf contains garbage, and risks a memory leak if errbuf already has a non-STRBUF_INIT state. It should be the caller's responsibility to make sure errbuf is not garbage, since garbage content is easily avoidable with STRBUF_INIT. Signed-off-by: Matthew DeVore <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 696aa73 commit cc0b05a

File tree

1 file changed

+2
-4
lines changed

1 file changed

+2
-4
lines changed

list-objects-filter-options.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ static int gently_parse_list_objects_filter(
3030

3131
if (filter_options->choice) {
3232
if (errbuf) {
33-
strbuf_init(errbuf, 0);
3433
strbuf_addstr(
3534
errbuf,
3635
_("multiple filter-specs cannot be combined"));
@@ -71,10 +70,9 @@ static int gently_parse_list_objects_filter(
7170
return 0;
7271
}
7372

74-
if (errbuf) {
75-
strbuf_init(errbuf, 0);
73+
if (errbuf)
7674
strbuf_addf(errbuf, "invalid filter-spec '%s'", arg);
77-
}
75+
7876
memset(filter_options, 0, sizeof(*filter_options));
7977
return 1;
8078
}

0 commit comments

Comments
 (0)