]> git.proxmox.com Git - mirror_libseccomp.git/commitdiff
db: fix a leak found by clang
authorPaul Moore <paul@paul-moore.com>
Tue, 5 Feb 2019 21:06:10 +0000 (16:06 -0500)
committerPaul Moore <paul@paul-moore.com>
Tue, 5 Feb 2019 21:06:10 +0000 (16:06 -0500)
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 <paul@paul-moore.com>
src/db.c

index 8fed3ad1b2936151e21c9c2258636101a54e4652..1173534f19429f738dbda346f8e137eb7ebed7fb 100644 (file)
--- 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;
 }