summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 209e756)
raw | patch | inline | side by side (parent: 209e756)
author | Junio C Hamano <junkio@cox.net> | |
Wed, 27 Sep 2006 23:27:10 +0000 (16:27 -0700) | ||
committer | Junio C Hamano <junkio@cox.net> | |
Wed, 27 Sep 2006 23:27:10 +0000 (16:27 -0700) |
Signed-off-by: Junio C Hamano <junkio@cox.net>
builtin-grep.c | patch | blob | history | |
grep.c | patch | blob | history | |
grep.h | patch | blob | history |
diff --git a/builtin-grep.c b/builtin-grep.c
index 671878817386c72f16fe64cc62b6fa8daa62f102..4205e5d38dea6dee2d815a7434f87eacd089e4a9 100644 (file)
--- a/builtin-grep.c
+++ b/builtin-grep.c
else
hit |= grep_file(opt, ce->name);
}
+ free_grep_patterns(opt);
return hit;
}
if (grep_object(&opt, paths, real_obj, list.objects[i].name))
hit = 1;
}
+ free_grep_patterns(&opt);
return !hit;
}
index cc8d6846a59563b6b902f576262ec97b73f01562..2c740bde50635df96a1ac45e4dd0f2179ea69519 100644 (file)
--- a/grep.c
+++ b/grep.c
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) {
index 0b503ea6657692672c3365f3090151cc5e9e6681..af9098cfe8699680aeaa11790dad3e8d556ed395 100644 (file)
--- a/grep.h
+++ b/grep.h
extern void append_grep_pattern(struct grep_opt *opt, const char *pat, const char *origin, int no, enum grep_pat_token t);
extern void compile_grep_patterns(struct grep_opt *opt);
+extern void free_grep_patterns(struct grep_opt *opt);
extern int grep_buffer(struct grep_opt *opt, const char *name, char *buf, unsigned long size);
#endif