From: Sebastian Harl Date: Sun, 6 Apr 2014 12:04:48 +0000 (+0200) Subject: frontend: Fixed memory holes in the parser. X-Git-Tag: sysdb-0.1.0~138 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=495dfe8178398c64d78f1476fe505fb0e36eefdc;p=sysdb.git frontend: Fixed memory holes in the parser. --- diff --git a/src/frontend/connection-private.h b/src/frontend/connection-private.h index f2d85f2..574049e 100644 --- a/src/frontend/connection-private.h +++ b/src/frontend/connection-private.h @@ -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" */ diff --git a/src/frontend/grammar.y b/src/frontend/grammar.y index fd268ba..abc5165 100644 --- a/src/frontend/grammar.y +++ b/src/frontend/grammar.y @@ -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; } diff --git a/src/frontend/parser.c b/src/frontend/parser.c index 6504a66..76382d3 100644 --- a/src/frontend/parser.c +++ b/src/frontend/parser.c @@ -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;