netfilter-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [nft PATCH 1/3] nft: use own allocation function
@ 2019-06-27 10:50 Arturo Borrero Gonzalez
  2019-06-27 10:50 ` [nft PATCH 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-06-27 10:50 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 introduce a new allocation function in the nft frontend.
This results in a bit of code duplication, but given the simplicity of the code,
I don't think it's a big deal.

Other possible approach would be to have xzalloc() become part of libnftables
public API, but that is a much worse scenario I think.

Signed-off-by: Arturo Borrero Gonzalez <arturo@netfilter.org>
---
 src/main.c |   15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/src/main.c b/src/main.c
index cbfd69a..d5857e8 100644
--- a/src/main.c
+++ b/src/main.c
@@ -19,9 +19,24 @@
 #include <sys/types.h>
 
 #include <nftables/libnftables.h>
+#include <nftables.h>
 #include <utils.h>
 #include <cli.h>
 
+void *xzalloc(size_t size)
+{
+	void *ptr;
+
+	ptr = malloc(size);
+	if (ptr == NULL) {
+		fprintf(stderr, "%s:%u: Memory allocation failure\n",
+			__FILE__, __LINE__);
+		exit(NFT_EXIT_NOMEM);
+	}
+	memset(ptr, 0, size);
+	return ptr;
+}
+
 static struct nft_ctx *nft;
 
 enum opt_vals {


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

end of thread, other threads:[~2019-06-27 12:20 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-06-27 10:50 [nft PATCH 1/3] nft: use own allocation function Arturo Borrero Gonzalez
2019-06-27 10:50 ` [nft PATCH 2/3] libnftables: reallocate definition of nft_print() and nft_gmp_print() Arturo Borrero Gonzalez
2019-06-27 10:59   ` Arturo Borrero Gonzalez
2019-06-27 11:22     ` Florian Westphal
2019-06-27 12:20   ` Pablo Neira Ayuso
2019-06-27 10:50 ` [nft PATCH 3/3] libnftables: export public symbols only Arturo Borrero Gonzalez
2019-06-27 11:21   ` Florian Westphal
2019-06-27 11:20 ` [nft PATCH 1/3] nft: use own allocation function Florian Westphal
2019-06-27 12:19 ` Pablo Neira Ayuso

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).