]> git.ipfire.org Git - thirdparty/nftables.git/commitdiff
cache: memleak list of chain
authorPablo Neira Ayuso <pablo@netfilter.org>
Tue, 2 Mar 2021 11:40:27 +0000 (12:40 +0100)
committerPablo Neira Ayuso <pablo@netfilter.org>
Fri, 5 Mar 2021 19:42:21 +0000 (20:42 +0100)
Release chain list from the error path.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
src/rule.c

index 367c5c8be9521975290320f5141ff298527f4420..cf4d2cbef27b96caf81b31287e9bb77110ee407b 100644 (file)
@@ -170,32 +170,42 @@ static int cache_init_objects(struct netlink_ctx *ctx, unsigned int flags)
                if (flags & NFT_CACHE_SET_BIT) {
                        ret = netlink_list_sets(ctx, &table->handle);
                        list_splice_tail_init(&ctx->list, &table->sets);
-                       if (ret < 0)
-                               return -1;
+                       if (ret < 0) {
+                               ret = -1;
+                               goto cache_fails;
+                       }
                }
                if (flags & NFT_CACHE_SETELEM_BIT) {
                        list_for_each_entry(set, &table->sets, list) {
                                ret = netlink_list_setelems(ctx, &set->handle,
                                                            set);
-                               if (ret < 0)
-                                       return -1;
+                               if (ret < 0) {
+                                       ret = -1;
+                                       goto cache_fails;
+                               }
                        }
                }
                if (flags & NFT_CACHE_CHAIN_BIT) {
                        ret = chain_cache_init(ctx, table, chain_list);
-                       if (ret < 0)
-                               return -1;
+                       if (ret < 0) {
+                               ret = -1;
+                               goto cache_fails;
+                       }
                }
                if (flags & NFT_CACHE_FLOWTABLE_BIT) {
                        ret = netlink_list_flowtables(ctx, &table->handle);
-                       if (ret < 0)
-                               return -1;
+                       if (ret < 0) {
+                               ret = -1;
+                               goto cache_fails;
+                       }
                        list_splice_tail_init(&ctx->list, &table->flowtables);
                }
                if (flags & NFT_CACHE_OBJECT_BIT) {
                        ret = netlink_list_objs(ctx, &table->handle);
-                       if (ret < 0)
-                               return -1;
+                       if (ret < 0) {
+                               ret = -1;
+                               goto cache_fails;
+                       }
                        list_splice_tail_init(&ctx->list, &table->objs);
                }
 
@@ -208,15 +218,18 @@ static int cache_init_objects(struct netlink_ctx *ctx, unsigned int flags)
                                                        rule->handle.chain.name);
                                list_move_tail(&rule->list, &chain->rules);
                        }
-                       if (ret < 0)
-                               return -1;
+                       if (ret < 0) {
+                               ret = -1;
+                               goto cache_fails;
+                       }
                }
        }
 
+cache_fails:
        if (flags & NFT_CACHE_CHAIN_BIT)
                nftnl_chain_list_free(chain_list);
 
-       return 0;
+       return ret;
 }
 
 static int cache_init(struct netlink_ctx *ctx, unsigned int flags)