Mercurial > hg > dmlib
changeset 836:85442780089f
Fix reallocation.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Sun, 13 Jul 2014 17:41:47 +0300 |
parents | a75ffe7a02b9 |
children | 5333dd4a99e4 |
files | src/dmstring.c |
diffstat | 1 files changed, 7 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/src/dmstring.c Sun Jul 13 17:40:45 2014 +0300 +++ b/src/dmstring.c Sun Jul 13 17:41:47 2014 +0300 @@ -108,7 +108,7 @@ char *dm_strdup_vprintf(const char *fmt, va_list args) { int size = 64; - char *buf; + char *buf, *tmp; if ((buf = dmMalloc(size)) == NULL) return NULL; @@ -128,8 +128,13 @@ else size *= 2; - if ((buf = dmRealloc(buf, size)) == NULL) + if ((tmp = dmRealloc(buf, size)) == NULL) + { + dmFree(buf); return NULL; + } + else + buf = tmp; } }