From: Pablo Neira Ayuso <pablo@netfilter.org>
To: netfilter-devel@vger.kernel.org
Cc: kaber@trash.net
Subject: [PATCH nft] utils: indicate file and line on memory allocation errors
Date: Tue, 4 Nov 2014 14:29:53 +0100 [thread overview]
Message-ID: <1415107793-5299-1-git-send-email-pablo@netfilter.org> (raw)
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
reply other threads:[~2014-11-04 13:28 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1415107793-5299-1-git-send-email-pablo@netfilter.org \
--to=pablo@netfilter.org \
--cc=kaber@trash.net \
--cc=netfilter-devel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).