From f0731b34a736d266ca48edd0f98f5d8237253eca Mon Sep 17 00:00:00 2001 From: Sebastian Harl Date: Wed, 23 Apr 2014 10:22:59 +0200 Subject: [PATCH] parser: Don't leak memory when building nested matchers. --- src/core/store_lookup.c | 9 ++++++++- src/frontend/grammar.y | 7 +++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/core/store_lookup.c b/src/core/store_lookup.c index bb32157..2affaa9 100644 --- a/src/core/store_lookup.c +++ b/src/core/store_lookup.c @@ -681,7 +681,14 @@ sdb_store_matcher_parse_cmp(const char *obj_type, const char *attr, /* service = */ NULL, sdb_store_attr_matcher(matcher, matcher_re, NULL, NULL)); - if (m && inv) { + if (! m) + return NULL; + + /* pass ownership to the host matcher */ + sdb_object_deref(SDB_OBJ(HOST_M(m)->service)); + sdb_object_deref(SDB_OBJ(HOST_M(m)->attr)); + + if (inv) { sdb_store_matcher_t *tmp; tmp = sdb_store_inv_matcher(m); /* pass ownership to the inverse matcher */ diff --git a/src/frontend/grammar.y b/src/frontend/grammar.y index a261c4c..450a20f 100644 --- a/src/frontend/grammar.y +++ b/src/frontend/grammar.y @@ -255,16 +255,21 @@ matcher: matcher AND matcher { $$ = sdb_store_con_matcher($1, $3); + sdb_object_deref(SDB_OBJ($1)); + sdb_object_deref(SDB_OBJ($3)); } | matcher OR matcher { $$ = sdb_store_dis_matcher($1, $3); + sdb_object_deref(SDB_OBJ($1)); + sdb_object_deref(SDB_OBJ($3)); } | NOT matcher { $$ = sdb_store_inv_matcher($2); + sdb_object_deref(SDB_OBJ($2)); } | compare_matcher @@ -316,6 +321,8 @@ compare_matcher: %% +/* XXX: on parse errors, allocated objects, strings, etc. need to be freed */ + void sdb_fe_yyerror(YYLTYPE *lval, sdb_fe_yyscan_t scanner, const char *msg) { -- 2.30.2