diff options
author | Guillaume Nault <g.nault@alphalink.fr> | 2013-07-10 12:54:28 +0200 |
---|---|---|
committer | Dmitry Kozlov <xeb@mail.ru> | 2013-07-18 22:57:36 +0400 |
commit | 80a7f62ad9c3fabb929e94ebb0745dcb4e42b93a (patch) | |
tree | 224fae9dc9271107b73a1c79200db33d114f19e9 /accel-pppd/memdebug.c | |
parent | 5b095342160fc5c7e7e5a42b202a2e7d535bb757 (diff) | |
download | accel-ppp-80a7f62ad9c3fabb929e94ebb0745dcb4e42b93a.tar.gz accel-ppp-80a7f62ad9c3fabb929e94ebb0745dcb4e42b93a.zip |
memdbg: Handle memory allocation failures
Report memory allocation failures in md_alloc() by returning a NULL
pointer.
Signed-off-by: Guillaume Nault <g.nault@alphalink.fr>
Diffstat (limited to 'accel-pppd/memdebug.c')
-rw-r--r-- | accel-pppd/memdebug.c | 9 |
1 files changed, 6 insertions, 3 deletions
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) |