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>
This commit is contained in:
Matthew DeVore 2018-10-05 14:31:26 -07:00 коммит произвёл Junio C Hamano
Родитель 696aa73905
Коммит cc0b05a4cc
1 изменённых файлов: 2 добавлений и 4 удалений

Просмотреть файл

@ -30,7 +30,6 @@ static int gently_parse_list_objects_filter(
if (filter_options->choice) {
if (errbuf) {
strbuf_init(errbuf, 0);
strbuf_addstr(
errbuf,
_("multiple filter-specs cannot be combined"));
@ -71,10 +70,9 @@ static int gently_parse_list_objects_filter(
return 0;
}
if (errbuf) {
strbuf_init(errbuf, 0);
if (errbuf)
strbuf_addf(errbuf, "invalid filter-spec '%s'", arg);
}
memset(filter_options, 0, sizeof(*filter_options));
return 1;
}