diff options
author | Junio C Hamano <gitster@pobox.com> | 2023-02-22 23:55:45 +0100 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2023-02-22 23:55:45 +0100 |
commit | 72972ea0b978f20b335339d18e497da617398967 (patch) | |
tree | 770e98011633bc27a1ef54b51cd2752b0f80acc6 /grep.c | |
parent | Merge branch 'jk/doc-ls-remote-matching' (diff) | |
parent | push: free_refs() the "local_refs" in set_refspecs() (diff) | |
download | git-72972ea0b978f20b335339d18e497da617398967.tar.xz git-72972ea0b978f20b335339d18e497da617398967.zip |
Merge branch 'ab/various-leak-fixes'
Leak fixes.
* ab/various-leak-fixes:
push: free_refs() the "local_refs" in set_refspecs()
push: refactor refspec_append_mapped() for subsequent leak-fix
receive-pack: release the linked "struct command *" list
grep API: plug memory leaks by freeing "header_list"
grep.c: refactor free_grep_patterns()
builtin/merge.c: free "&buf" on "Your local changes..." error
builtin/merge.c: use fixed strings, not "strbuf", fix leak
show-branch: free() allocated "head" before return
commit-graph: fix a parse_options_concat() leak
http-backend.c: fix cmd_main() memory leak, refactor reg{exec,free}()
http-backend.c: fix "dir" and "cmd_arg" leaks in cmd_main()
worktree: fix a trivial leak in prune_worktrees()
repack: fix leaks on error with "goto cleanup"
name-rev: don't xstrdup() an already dup'd string
various: add missing clear_pathspec(), fix leaks
clone: use free() instead of UNLEAK()
commit-graph: use free_commit_graph() instead of UNLEAK()
bundle.c: don't leak the "args" in the "struct child_process"
tests: mark tests as passing with SANITIZE=leak
Diffstat (limited to 'grep.c')
-rw-r--r-- | grep.c | 15 |
1 files changed, 10 insertions, 5 deletions
@@ -815,11 +815,11 @@ static void free_pattern_expr(struct grep_expr *x) free(x); } -void free_grep_patterns(struct grep_opt *opt) +static void free_grep_pat(struct grep_pat *pattern) { struct grep_pat *p, *n; - for (p = opt->pattern_list; p; p = n) { + for (p = pattern; p; p = n) { n = p->next; switch (p->token) { case GREP_PATTERN: /* atom */ @@ -836,10 +836,15 @@ void free_grep_patterns(struct grep_opt *opt) } free(p); } +} - if (!opt->pattern_expression) - return; - free_pattern_expr(opt->pattern_expression); +void free_grep_patterns(struct grep_opt *opt) +{ + free_grep_pat(opt->pattern_list); + free_grep_pat(opt->header_list); + + if (opt->pattern_expression) + free_pattern_expr(opt->pattern_expression); } static const char *end_of_line(const char *cp, unsigned long *left) |