]> git.ipfire.org Git - thirdparty/iptables.git/commitdiff
nft-shared: Use xtables_calloc()
authorPhil Sutter <phil@nwl.cc>
Mon, 24 Sep 2018 17:25:26 +0000 (19:25 +0200)
committerFlorian Westphal <fw@strlen.de>
Tue, 25 Sep 2018 14:26:34 +0000 (16:26 +0200)
This simplifies code a bit since it takes care of checking for
out-of-memory conditions.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Florian Westphal <fw@strlen.de>
iptables/nft-shared.c

index fdd4522ce24f4669448e11e696e09f5282c6a61e..492e4ec124a79c6d546b50cba387294f7d766d2c 100644 (file)
@@ -319,11 +319,7 @@ void nft_parse_target(struct nft_xt_ctx *ctx, struct nftnl_expr *e)
 
        size = XT_ALIGN(sizeof(struct xt_entry_target)) + tg_len;
 
-       t = calloc(1, size);
-       if (t == NULL) {
-               fprintf(stderr, "OOM");
-               exit(EXIT_FAILURE);
-       }
+       t = xtables_calloc(1, size);
        memcpy(&t->data, targinfo, tg_len);
        t->u.target_size = size;
        t->u.user.revision = nftnl_expr_get_u32(e, NFTNL_EXPR_TG_REV);
@@ -361,12 +357,7 @@ void nft_parse_match(struct nft_xt_ctx *ctx, struct nftnl_expr *e)
        if (match == NULL)
                return;
 
-       m = calloc(1, sizeof(struct xt_entry_match) + mt_len);
-       if (m == NULL) {
-               fprintf(stderr, "OOM");
-               exit(EXIT_FAILURE);
-       }
-
+       m = xtables_calloc(1, sizeof(struct xt_entry_match) + mt_len);
        memcpy(&m->data, mt_info, mt_len);
        m->u.match_size = mt_len + XT_ALIGN(sizeof(struct xt_entry_match));
        m->u.user.revision = nftnl_expr_get_u32(e, NFTNL_EXPR_TG_REV);