Code

frontend: Fixed memory holes in the parser.
authorSebastian Harl <sh@tokkee.org>
Sun, 6 Apr 2014 12:04:48 +0000 (14:04 +0200)
committerSebastian Harl <sh@tokkee.org>
Sun, 6 Apr 2014 12:04:48 +0000 (14:04 +0200)
src/frontend/connection-private.h
src/frontend/grammar.y
src/frontend/parser.c

index f2d85f2ccdfd177e461032421a90eb181f870fdc..574049e3dde05b42d1dc1e0dd326242d45ff43bc 100644 (file)
@@ -103,12 +103,19 @@ conn_fetch_destroy(sdb_object_t *obj)
                free(CONN_FETCH(obj)->name);
 } /* conn_fetch_destroy */
 
+static void __attribute__((unused))
+conn_matcher_destroy(sdb_object_t *obj)
+{
+       if (CONN_MATCHER(obj)->matcher)
+               sdb_object_deref(SDB_OBJ(CONN_MATCHER(obj)->matcher));
+} /* conn_matcher_destroy */
+
 static void __attribute__((unused))
 conn_lookup_destroy(sdb_object_t *obj)
 {
        if (CONN_LOOKUP(obj)->matcher)
                sdb_object_deref(SDB_OBJ(CONN_LOOKUP(obj)->matcher));
-} /* conn_fetch_destroy */
+} /* conn_lookup_destroy */
 
 #ifdef __cplusplus
 } /* extern "C" */
index fd268baf3a9c6ce5126891c9ff6edbcc8af16e4f..abc51656934edcffc8c6f32ddf7320f985541d77 100644 (file)
@@ -111,6 +111,7 @@ statements:
                                sdb_fe_yyerror(&yylloc, scanner,
                                                YY_("syntax error, unexpected statement, "
                                                        "expecting expression"));
+                               sdb_object_deref(SDB_OBJ($3));
                                YYABORT;
                        }
 
@@ -127,6 +128,7 @@ statements:
                                sdb_fe_yyerror(&yylloc, scanner,
                                                YY_("syntax error, unexpected statement, "
                                                        "expecting expression"));
+                               sdb_object_deref(SDB_OBJ($1));
                                YYABORT;
                        }
 
@@ -143,6 +145,7 @@ statements:
                                sdb_fe_yyerror(&yylloc, scanner,
                                                YY_("syntax error, unexpected expression, "
                                                        "expecting statement"));
+                               sdb_object_deref(SDB_OBJ($1));
                                YYABORT;
                        }
 
@@ -210,6 +213,8 @@ lookup_statement:
                                snprintf(errmsg, sizeof(errmsg),
                                                YY_("unknown table %s"), $2);
                                sdb_fe_yyerror(&yylloc, scanner, errmsg);
+                               free($2); $2 = NULL;
+                               sdb_object_deref(SDB_OBJ($4));
                                YYABORT;
                        }
 
@@ -232,8 +237,8 @@ expression:
                                YYABORT;
                        }
 
-                       $$ = SDB_CONN_NODE(sdb_object_create_T(/* name = */ NULL,
-                                               conn_node_matcher_t));
+                       $$ = SDB_CONN_NODE(sdb_object_create_dT(/* name = */ NULL,
+                                               conn_node_matcher_t, conn_matcher_destroy));
                        $$->cmd = CONNECTION_EXPR;
 
                        if ((M(m)->type == MATCHER_HOST)
@@ -253,6 +258,7 @@ expression:
                                snprintf(errbuf, sizeof(errbuf),
                                                YY_("syntax error, unexpected matcher type %d"),
                                                M(m)->type);
+                               sdb_object_deref(SDB_OBJ($$));
                                sdb_fe_yyerror(&yylloc, scanner, errbuf);
                                YYABORT;
                        }
index 6504a66ea7a408b00522ab3ae94639f52e484df0..76382d34b099756b09348e0afa67ab013a9ab7ca 100644 (file)
@@ -120,6 +120,7 @@ sdb_fe_parse_matcher(const char *expr, int len)
        else
                m = NULL;
 
+       CONN_MATCHER(node)->matcher = NULL;
        sdb_llist_destroy(yyextra.parsetree);
        sdb_object_deref(SDB_OBJ(node));
        return m;