netfilter-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH nft] utils: indicate file and line on memory allocation errors
@ 2014-11-04 13:29 Pablo Neira Ayuso
  0 siblings, 0 replies; only message in thread
From: Pablo Neira Ayuso @ 2014-11-04 13:29 UTC (permalink / raw)
  To: netfilter-devel; +Cc: kaber

For example:

 src/netlink.c:179: Memory allocation failure

This shouldn't happen, so this allows us to identify at what point the
memory allocation failure has happened. It may be helpful to identify
bugs.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
---
 include/utils.h |    5 ++++-
 src/utils.c     |    4 ++--
 2 files changed, 6 insertions(+), 3 deletions(-)

diff --git a/include/utils.h b/include/utils.h
index cc5948c..15b2e39 100644
--- a/include/utils.h
+++ b/include/utils.h
@@ -76,7 +76,10 @@
 	(void) (&_max1 == &_max2);		\
 	_max1 > _max2 ? _max1 : _max2; })
 
-extern void memory_allocation_error(void) __noreturn;
+extern void __memory_allocation_error(const char *filename, uint32_t line) __noreturn;
+
+#define memory_allocation_error()		\
+	__memory_allocation_error(__FILE__, __LINE__);
 
 extern void xfree(const void *ptr);
 extern void *xmalloc(size_t size);
diff --git a/src/utils.c b/src/utils.c
index 96ff419..88708e7 100644
--- a/src/utils.c
+++ b/src/utils.c
@@ -18,9 +18,9 @@
 #include <nftables.h>
 #include <utils.h>
 
-void __noreturn memory_allocation_error(void)
+void __noreturn __memory_allocation_error(const char *filename, uint32_t line)
 {
-	fprintf(stderr, "Memory allocation failure\n");
+	fprintf(stderr, "%s:%u: Memory allocation failure\n", filename, line);
 	exit(NFT_EXIT_NOMEM);
 }
 
-- 
1.7.10.4


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2014-11-04 13:28 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-11-04 13:29 [PATCH nft] utils: indicate file and line on memory allocation errors 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).