[PATCH] --whole-pkg: more fine grained pattern memory management

Stefano Zacchiroli zack at upsilon.cc
Thu Jan 29 12:06:35 UTC 2009


Avoid allocating extra, unneeded memory, also based on arbitrary magic
numbers. Rather, rely on the current pattern length + the lengths of
the added delimiters.
---
 lib/predicate.c |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)

diff --git a/lib/predicate.c b/lib/predicate.c
index 14f8500..e2318d3 100644
--- a/lib/predicate.c
+++ b/lib/predicate.c
@@ -50,7 +50,8 @@ void predicate_finish_atom(struct predicate * p)
 {
 	struct atom * atom =  get_current_atom(p);
 	char * regex_pat = NULL;
-	int regex_patlen = atom->patlen + 30;
+	int regex_patlen = atom->patlen + strlen(RE_PKG_BEGIN)
+				+ strlen(RE_PKG_END) + 1;
 	debug_message("predicate_finish_atom", 0);
 	if (atom->field_name != 0) {
                 char * repl = strchr(atom->field_name, ':');
-- 
1.5.6.5


--tThc/1wpZn/ma/RB--





More information about the Dctrl-tools-devel mailing list