Skip to content

Commit 6d82437

Browse files
pks-tgitster
authored andcommitted
grep: fix leaking grep pattern
When creating a pattern via `create_grep_pat()` we allocate the pattern member of the structure regardless of the token type. But later, when we try to free the structure, we free the pattern member conditionally on the token type and thus leak memory. Plug this leak. The leak is exposed by t7814, but plugging it alone does not make the whole test suite pass. Signed-off-by: Patrick Steinhardt <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent f8d2ca7 commit 6d82437

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

grep.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -843,11 +843,11 @@ static void free_grep_pat(struct grep_pat *pattern)
843843
free_pcre2_pattern(p);
844844
else
845845
regfree(&p->regexp);
846-
free(p->pattern);
847846
break;
848847
default:
849848
break;
850849
}
850+
free(p->pattern);
851851
free(p);
852852
}
853853
}

0 commit comments

Comments
 (0)