]> git.ipfire.org Git - thirdparty/git.git/commit
grep.c: refactor free_grep_patterns()
authorÆvar Arnfjörð Bjarmason <avarab@gmail.com>
Mon, 6 Feb 2023 23:07:50 +0000 (00:07 +0100)
committerJunio C Hamano <gitster@pobox.com>
Mon, 6 Feb 2023 23:34:39 +0000 (15:34 -0800)
commit891c9965fbc05848fb66444274e39c7ae2c6f321
tree94a5a608e9c82da7be3deef0b9ec70e2135e492d
parent41211db10f27de1a21ef2fd287f168ef25231275
grep.c: refactor free_grep_patterns()

Refactor the free_grep_patterns() function to split out the freeing of
the "struct grep_pat" it contains. Right now we're only freeing the
"pattern_list", but we should be freeing another member of the same
type, which we'll do in the subsequent commit.

Let's also replace the "return" if we don't have an
"opt->pattern_expression" with a conditional call of
free_pattern_expr().

Before db84376f981 (grep.c: remove "extended" in favor of
"pattern_expression", fix segfault, 2022-10-11) the pattern here was:

if (!x)
return;
free_pattern_expr(y);

While at it, instead of:

if (!x)
return;
free_pattern_expr(x);

Let's instead do:

if (x)
free_pattern_expr(x);

This will make it easier to free additional members from
free_grep_patterns() in the future.

Helped-by: Elijah Newren <newren@gmail.com>
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
grep.c