From: Patrick McHardy Date: Fri, 20 Mar 2009 15:23:50 +0000 (+0100) Subject: Release scopes during cleanup X-Git-Tag: v0.099~194 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7feffa0ed35e4125f272edded092b890234a794b;p=thirdparty%2Fnftables.git Release scopes during cleanup Properly release the user-defined symbols. Signed-off-by: Patrick McHardy --- diff --git a/include/rule.h b/include/rule.h index 4e5da064..01eeb210 100644 --- a/include/rule.h +++ b/include/rule.h @@ -35,6 +35,7 @@ struct scope { }; extern struct scope *scope_init(struct scope *scope, const struct scope *parent); +extern void scope_release(const struct scope *scope); /** * struct symbol diff --git a/src/main.c b/src/main.c index f7686ae3..00f594f6 100644 --- a/src/main.c +++ b/src/main.c @@ -195,6 +195,7 @@ int main(int argc, char * const *argv) } out: scanner_destroy(scanner); + scope_release(&state.top_scope); erec_print_list(stdout, &msgs); xfree(buf); diff --git a/src/rule.c b/src/rule.c index 8efbd887..6f322b8b 100644 --- a/src/rule.c +++ b/src/rule.c @@ -75,6 +75,18 @@ struct scope *scope_init(struct scope *scope, const struct scope *parent) return scope; } +void scope_release(const struct scope *scope) +{ + struct symbol *sym, *next; + + list_for_each_entry_safe(sym, next, &scope->symbols, list) { + list_del(&sym->list); + xfree(sym->identifier); + expr_free(sym->expr); + xfree(sym); + } +} + void symbol_bind(struct scope *scope, const char *identifier, struct expr *expr) { struct symbol *sym; @@ -118,6 +130,7 @@ void chain_free(struct chain *chain) list_for_each_entry_safe(rule, next, &chain->rules, list) rule_free(rule); handle_free(&chain->handle); + scope_release(&chain->scope); xfree(chain); } @@ -165,6 +178,7 @@ void table_free(struct table *table) list_for_each_entry_safe(chain, next, &table->chains, list) chain_free(chain); handle_free(&table->handle); + scope_release(&table->scope); xfree(table); }