summaryrefslogtreecommitdiff
path: root/grep.c
diff options
context:
space:
mode:
authorJunio C Hamano <junkio@cox.net>2006-09-27 16:27:10 -0700
committerJunio C Hamano <junkio@cox.net>2006-09-27 16:27:10 -0700
commitb48fb5b6a950a6757b790e9160967065a3e03978 (patch)
tree7ba2dda07f7bd01000f2c198b15bc8f6174998c1 /grep.c
parent209e7569313aa045da6d55e333c884e49e7d8fb2 (diff)
downloadgit-b48fb5b6a950a6757b790e9160967065a3e03978.tar.gz
grep: free expressions and patterns when done.
Signed-off-by: Junio C Hamano <junkio@cox.net>
Diffstat (limited to 'grep.c')
-rw-r--r--grep.c42
1 files changed, 42 insertions, 0 deletions
diff --git a/grep.c b/grep.c
index cc8d6846a5..2c740bde50 100644
--- a/grep.c
+++ b/grep.c
@@ -167,6 +167,46 @@ void compile_grep_patterns(struct grep_opt *opt)
die("incomplete pattern expression: %s", p->pattern);
}
+static void free_pattern_expr(struct grep_expr *x)
+{
+ switch (x->node) {
+ case GREP_NODE_ATOM:
+ break;
+ case GREP_NODE_NOT:
+ free_pattern_expr(x->u.unary);
+ break;
+ case GREP_NODE_AND:
+ case GREP_NODE_OR:
+ free_pattern_expr(x->u.binary.left);
+ free_pattern_expr(x->u.binary.right);
+ break;
+ }
+ free(x);
+}
+
+void free_grep_patterns(struct grep_opt *opt)
+{
+ struct grep_pat *p, *n;
+
+ for (p = opt->pattern_list; p; p = n) {
+ n = p->next;
+ switch (p->token) {
+ case GREP_PATTERN: /* atom */
+ case GREP_PATTERN_HEAD:
+ case GREP_PATTERN_BODY:
+ regfree(&p->regexp);
+ break;
+ default:
+ break;
+ }
+ free(p);
+ }
+
+ if (!opt->extended)
+ return;
+ free_pattern_expr(opt->pattern_expression);
+}
+
static char *end_of_line(char *cp, unsigned long *left)
{
unsigned long l = *left;
@@ -439,6 +479,8 @@ int grep_buffer(struct grep_opt *opt, const char *name, char *buf, unsigned long
lno++;
}
+ free(prev);
+
if (opt->status_only)
return 0;
if (opt->unmatch_name_only) {