From 4925a61bf843462f987def1820a4ad676100d421 Mon Sep 17 00:00:00 2001 From: Guillaume Nault Date: Wed, 10 Jul 2013 12:54:46 +0200 Subject: memdbg: Handle memory allocation failures in strdup() Don't fail if _md_malloc() returns NULL. Signed-off-by: Guillaume Nault --- accel-pppd/memdebug.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'accel-pppd/memdebug.c') diff --git a/accel-pppd/memdebug.c b/accel-pppd/memdebug.c index 67c8498..8c3c494 100644 --- a/accel-pppd/memdebug.c +++ b/accel-pppd/memdebug.c @@ -142,9 +142,13 @@ void __export *md_realloc(void *ptr, size_t size, const char *fname, int line) char __export *md_strdup(const char *ptr, const char *fname, int line) { - struct mem_t *mem = _md_malloc(strlen(ptr) + 1, fname, line); - memcpy(mem->data, ptr, strlen(ptr) + 1); - return mem->data; + size_t len = strlen(ptr); + char *str = md_malloc(len + 1, fname, line); + + if (str) + memcpy(str, ptr, len + 1); + + return str; } char __export *md_strndup(const char *ptr, size_t n, const char *fname, int line) -- cgit v1.2.3