diff options
author | Guillaume Nault <g.nault@alphalink.fr> | 2013-07-10 12:54:46 +0200 |
---|---|---|
committer | Dmitry Kozlov <xeb@mail.ru> | 2013-07-18 22:57:36 +0400 |
commit | 4925a61bf843462f987def1820a4ad676100d421 (patch) | |
tree | d525dbe14d08af022cadf78d424eaa0f04781000 /accel-pppd | |
parent | 16b4d40a0f52eed4fd7def096a443670eab96b66 (diff) | |
download | accel-ppp-4925a61bf843462f987def1820a4ad676100d421.tar.gz accel-ppp-4925a61bf843462f987def1820a4ad676100d421.zip |
memdbg: Handle memory allocation failures in strdup()
Don't fail if _md_malloc() returns NULL.
Signed-off-by: Guillaume Nault <g.nault@alphalink.fr>
Diffstat (limited to 'accel-pppd')
-rw-r--r-- | accel-pppd/memdebug.c | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/accel-pppd/memdebug.c b/accel-pppd/memdebug.c index 67c84985..8c3c494f 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) |