]> git.ipfire.org Git - thirdparty/tor.git/commitdiff
Fix memory leak in test_util_asprintf
authorNick Mathewson <nickm@torproject.org>
Sat, 26 Apr 2014 04:13:27 +0000 (00:13 -0400)
committerNick Mathewson <nickm@torproject.org>
Sat, 26 Apr 2014 04:13:27 +0000 (00:13 -0400)
src/test/test_util.c

index 6d6b6dbdf84287b5270b46cc98f0e3e4f572ea00..256d8499191a8a40b4490c51e252dd551f60a6d5 100644 (file)
@@ -2241,18 +2241,21 @@ test_util_asprintf(void *ptr)
   test_assert(cp);
   test_streq("simple string 100% safe", cp);
   test_eq(strlen(cp), r);
+  tor_free(cp);
 
   /* empty string */
   r = tor_asprintf(&cp, "%s", "");
   test_assert(cp);
   test_streq("", cp);
   test_eq(strlen(cp), r);
+  tor_free(cp);
 
   /* numbers (%i) */
   r = tor_asprintf(&cp, "I like numbers-%2i, %i, etc.", -1, 2);
   test_assert(cp);
   test_streq("I like numbers--1, 2, etc.", cp);
   test_eq(strlen(cp), r);
+  /* don't free cp; next test uses it. */
 
   /* numbers (%d) */
   r = tor_asprintf(&cp2, "First=%d, Second=%d", 101, 202);