From e438b9766fcc86d9847312ff05f1d1dac61acf1f Mon Sep 17 00:00:00 2001 From: Phil Sutter Date: Tue, 31 Aug 2021 12:29:43 +0200 Subject: nft: Use xtables_{m,c}alloc() everywhere Make use of libxtables allocators where sensible to have implicit error checking. Leave library-internal calls in place to not create unexpected program exit points for users, apart from xt_xlate_alloc() as that function called xtables_error() in error case which exits by itself already. Signed-off-by: Phil Sutter --- iptables/xtables-eb.c | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) (limited to 'iptables/xtables-eb.c') diff --git a/iptables/xtables-eb.c b/iptables/xtables-eb.c index 6e35f58e..6e5ecd48 100644 --- a/iptables/xtables-eb.c +++ b/iptables/xtables-eb.c @@ -274,9 +274,7 @@ static struct option *merge_options(struct option *oldopts, ebtables_globals.option_offset += OPTION_OFFSET; *options_offset = ebtables_globals.option_offset; - merge = malloc(sizeof(struct option) * (num_new + num_old + 1)); - if (!merge) - return NULL; + merge = xtables_malloc(sizeof(struct option) * (num_new + num_old + 1)); memcpy(merge, oldopts, num_old * sizeof(struct option)); for (i = 0; i < num_new; i++) { merge[num_old + i] = newopts[i]; @@ -571,10 +569,7 @@ void ebt_add_match(struct xtables_match *m, m->mflags = 0; /* glue code for watchers */ - newnode = calloc(1, sizeof(struct ebt_match)); - if (newnode == NULL) - xtables_error(OTHER_PROBLEM, "Unable to alloc memory"); - + newnode = xtables_calloc(1, sizeof(struct ebt_match)); newnode->ismatch = true; newnode->u.match = newm; @@ -603,10 +598,7 @@ void ebt_add_watcher(struct xtables_target *watcher, watcher->tflags = 0; - newnode = calloc(1, sizeof(struct ebt_match)); - if (newnode == NULL) - xtables_error(OTHER_PROBLEM, "Unable to alloc memory"); - + newnode = xtables_calloc(1, sizeof(struct ebt_match)); newnode->u.watcher = clone; for (matchp = &cs->match_list; *matchp; matchp = &(*matchp)->next) -- cgit v1.2.3