netfilter-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [nft PATCH v2 1/3] nft: don't use xzalloc()
@ 2019-07-01 10:52 Arturo Borrero Gonzalez
  2019-07-01 10:53 ` [nft PATCH v2 2/3] libnftables: reallocate definition of nft_print() and nft_gmp_print() Arturo Borrero Gonzalez
                   ` (3 more replies)
  0 siblings, 4 replies; 9+ messages in thread
From: Arturo Borrero Gonzalez @ 2019-07-01 10:52 UTC (permalink / raw)
  To: netfilter-devel

In the current setup, nft (the frontend object) is using the xzalloc() function
from libnftables, which does not makes sense, as this is typically an internal
helper function.

In order to don't use this public libnftables symbol (a later patch just
removes it), let's use calloc() directly in the nft frontend.

Signed-off-by: Arturo Borrero Gonzalez <arturo@netfilter.org>
---
v2: use calloc() instead of re-defining xzalloc() per Pablo's suggestion.

 src/main.c |    8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/src/main.c b/src/main.c
index cbfd69a..8e6c897 100644
--- a/src/main.c
+++ b/src/main.c
@@ -19,6 +19,7 @@
 #include <sys/types.h>
 
 #include <nftables/libnftables.h>
+#include <nftables.h>
 #include <utils.h>
 #include <cli.h>
 
@@ -302,7 +303,12 @@ int main(int argc, char * const *argv)
 		for (len = 0, i = optind; i < argc; i++)
 			len += strlen(argv[i]) + strlen(" ");
 
-		buf = xzalloc(len);
+		buf = calloc(1, len);
+		if (buf == NULL) {
+			fprintf(stderr, "%s:%u: Memory allocation failure\n",
+				__FILE__, __LINE__);
+			exit(NFT_EXIT_NOMEM);
+		}
 		for (i = optind; i < argc; i++) {
 			strcat(buf, argv[i]);
 			if (i + 1 < argc)


^ permalink raw reply related	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2019-07-04 14:43 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-07-01 10:52 [nft PATCH v2 1/3] nft: don't use xzalloc() Arturo Borrero Gonzalez
2019-07-01 10:53 ` [nft PATCH v2 2/3] libnftables: reallocate definition of nft_print() and nft_gmp_print() Arturo Borrero Gonzalez
2019-07-01 18:25   ` Pablo Neira Ayuso
2019-07-01 10:53 ` [nft PATCH v2 3/3] libnftables: export public symbols only Arturo Borrero Gonzalez
2019-07-01 18:25   ` Pablo Neira Ayuso
2019-07-01 18:23 ` [nft PATCH v2 1/3] nft: don't use xzalloc() Pablo Neira Ayuso
2019-07-04 10:21 ` Phil Sutter
2019-07-04 12:41   ` Pablo Neira Ayuso
2019-07-04 14:43     ` Phil Sutter

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).