From f8854f990004e71ccb9955c33d88d82cdb97ea42 Mon Sep 17 00:00:00 2001 From: Paul Moore Date: Tue, 5 Feb 2019 16:06:10 -0500 Subject: [PATCH] db: fix a leak found by clang Fix a leak found by clang where we were not cleaning up properly in the error path. CC libseccomp_la-db.lo db.c:2020:2: warning: Potential leak of memory pointed to by 'rule_s' _db_snap_release(snap); ^~~~~~~~~~~~~~~~ Signed-off-by: Paul Moore --- src/db.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/db.c b/src/db.c index 8fed3ad..1173534 100644 --- a/src/db.c +++ b/src/db.c @@ -1947,7 +1947,7 @@ int db_col_transaction_start(struct db_filter_col *col) unsigned int iter; struct db_filter_snap *snap; struct db_filter *filter_o, *filter_s; - struct db_api_rule_list *rule_o, *rule_s, *rule_tmp; + struct db_api_rule_list *rule_o, *rule_s = NULL, *rule_tmp; /* allocate the snapshot */ snap = zmalloc(sizeof(*snap)); @@ -2004,6 +2004,7 @@ int db_col_transaction_start(struct db_filter_col *col) rule_tmp->next = rule_s; filter_s->rules = rule_s; } + rule_s = NULL; /* next rule */ rule_o = rule_o->next; @@ -2017,6 +2018,8 @@ int db_col_transaction_start(struct db_filter_col *col) return 0; trans_start_failure: + if (rule_s != NULL) + free(rule_s); _db_snap_release(snap); return -ENOMEM; } -- 2.39.5