changeset 56:b10f07101e67

Fix a memory leak in th_strdup_vprintf()
author Matti Hamalainen <ccr@tnsp.org>
date Sat, 26 May 2012 08:56:01 +0300
parents 300fba04b7ad
children c78757d6e440
files th_string.c
diffstat 1 files changed, 2 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/th_string.c	Sat May 26 03:47:07 2012 +0300
+++ b/th_string.c	Sat May 26 08:56:01 2012 +0300
@@ -59,7 +59,7 @@
 char *th_strdup_vprintf(const char *fmt, va_list args)
 {
     int size = 64;
-    char *buf, *nbuf = NULL;
+    char *buf;
 
     if ((buf = th_malloc(size)) == NULL)
         return NULL;
@@ -79,13 +79,8 @@
         else
             size *= 2;
 
-        if ((nbuf = th_realloc(nbuf, size)) == NULL)
-        {
-            th_free(buf);
+        if ((buf = th_realloc(buf, size)) == NULL)
             return NULL;
-        }
-
-        buf = nbuf;
     }
 }