This simplifies code a bit since it takes care of checking for
out-of-memory conditions.

Signed-off-by: Phil Sutter <p...@nwl.cc>
---
 iptables/nft-shared.c | 13 ++-----------
 1 file changed, 2 insertions(+), 11 deletions(-)

diff --git a/iptables/nft-shared.c b/iptables/nft-shared.c
index fdd4522ce24f4..492e4ec124a79 100644
--- a/iptables/nft-shared.c
+++ b/iptables/nft-shared.c
@@ -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);
-- 
2.19.0

Reply via email to