Code

parser: Don't leak memory when building nested matchers.
authorSebastian Harl <sh@tokkee.org>
Wed, 23 Apr 2014 08:22:59 +0000 (10:22 +0200)
committerSebastian Harl <sh@tokkee.org>
Wed, 23 Apr 2014 08:22:59 +0000 (10:22 +0200)
src/core/store_lookup.c
src/frontend/grammar.y

index bb32157402d8c047a20326aab81e069a4073e5f1..2affaa986f869e3c7514761857653203c291fefa 100644 (file)
@@ -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 */
index a261c4c81d3253320b9d8cf960378918f84d0249..450a20f34218ef1df4db9e713bb3b0247cddc0bb 100644 (file)
@@ -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)
 {