summaryrefslogtreecommitdiff
path: root/builtin/grep.c
diff options
context:
space:
mode:
authorRené Scharfe <rene.scharfe@lsrfire.ath.cx>2012-05-21 16:10:09 (GMT)
committerJunio C Hamano <gitster@pobox.com>2012-05-21 22:02:08 (GMT)
commitec83061156e18ce600384d3c57f90729a9295488 (patch)
tree7e4a385ecbbcd9f8de258a0e3ec4c33108afa671 /builtin/grep.c
parent526a858a99ace6698823740374edc3e35b87901a (diff)
downloadgit-ec83061156e18ce600384d3c57f90729a9295488.zip
git-ec83061156e18ce600384d3c57f90729a9295488.tar.gz
git-ec83061156e18ce600384d3c57f90729a9295488.tar.bz2
grep: stop leaking line strings with -f
When reading patterns from a file, we pass the lines as allocated string buffers to append_grep_pat() and never free them. That's not a problem because they are needed until the program ends anyway. However, now that the function duplicates the pattern string, we can reuse the strbuf after calling that function. This simplifies the code a bit and plugs a minor memory leak. Signed-off-by: Rene Scharfe <rene.scharfe@lsrfire.ath.cx> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'builtin/grep.c')
-rw-r--r--builtin/grep.c7
1 files changed, 2 insertions, 5 deletions
diff --git a/builtin/grep.c b/builtin/grep.c
index 871afaa..f139201 100644
--- a/builtin/grep.c
+++ b/builtin/grep.c
@@ -681,15 +681,12 @@ static int file_callback(const struct option *opt, const char *arg, int unset)
if (!patterns)
die_errno(_("cannot open '%s'"), arg);
while (strbuf_getline(&sb, patterns, '\n') == 0) {
- char *s;
- size_t len;
-
/* ignore empty line like grep does */
if (sb.len == 0)
continue;
- s = strbuf_detach(&sb, &len);
- append_grep_pat(grep_opt, s, len, arg, ++lno, GREP_PATTERN);
+ append_grep_pat(grep_opt, sb.buf, sb.len, arg, ++lno,
+ GREP_PATTERN);
}
if (!from_stdin)
fclose(patterns);