From 80a7f62ad9c3fabb929e94ebb0745dcb4e42b93a Mon Sep 17 00:00:00 2001 From: Guillaume Nault Date: Wed, 10 Jul 2013 12:54:28 +0200 Subject: memdbg: Handle memory allocation failures Report memory allocation failures in md_alloc() by returning a NULL pointer. Signed-off-by: Guillaume Nault --- accel-pppd/memdebug.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'accel-pppd/memdebug.c') diff --git a/accel-pppd/memdebug.c b/accel-pppd/memdebug.c index 8e9dd4bb..5ca7727e 100644 --- a/accel-pppd/memdebug.c +++ b/accel-pppd/memdebug.c @@ -25,7 +25,7 @@ (type *)( (char *)__mptr - offsetof(type,member) );}) -#define MAGIC1 0x1122334455667788llu +#define MAGIC1 UINT64_C(0x1122334455667788) struct mem_t { @@ -41,10 +41,13 @@ struct mem_t static LIST_HEAD(mem_list); static spinlock_t mem_list_lock = SPINLOCK_INITIALIZER; -struct mem_t *_md_malloc(size_t size, const char *fname, int line) +static struct mem_t *_md_malloc(size_t size, const char *fname, int line) { struct mem_t *mem = malloc(sizeof(*mem) + size + 8); + if (mem == NULL) + return NULL; + if (size > 4096) line = 0; @@ -66,7 +69,7 @@ void __export *md_malloc(size_t size, const char *fname, int line) { struct mem_t *mem = _md_malloc(size, fname, line); - return mem->data; + return mem ? mem->data : NULL; } void __export md_free(void *ptr, const char *fname, int line) -- cgit v1.2.3