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 <matvore@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Matthew DeVore committed Oct 5, 2018 at 14:31 UTC cc0b05a4cc54c30a5355a9da5d76b1879d960628
1 file changed +2 -4
list-objects-filter-options.c
+2 -4
@@ -30,7 +30,6 @@ static int gently_parse_list_objects_filter(
30
31 if (filter_options->choice) {
32 if (errbuf) {
33 - strbuf_init(errbuf, 0);
33 strbuf_addstr(
34 errbuf,
35 _("multiple filter-specs cannot be combined"));
@@ -71,10 +70,9 @@ static int gently_parse_list_objects_filter(
70 return 0;
71 }
72
74 - if (errbuf) {
75 - strbuf_init(errbuf, 0);
73 + if (errbuf)
74 strbuf_addf(errbuf, "invalid filter-spec '%s'", arg);
77 - }
75 +
76 memset(filter_options, 0, sizeof(*filter_options));
77 return 1;
78 }