[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [tor/release-0.2.4] Fix a small memory leak in the unit tests



commit 42fb61d172b172687cd57c86dd72b117f03f2136
Author: Nick Mathewson <nickm@xxxxxxxxxxxxxx>
Date:   Thu Mar 21 07:52:36 2013 -0400

    Fix a small memory leak in the unit tests
    
    Found by coverity; this is CID 992692.
---
 src/test/test_util.c |   26 +++++++++++++-------------
 1 files changed, 13 insertions(+), 13 deletions(-)

diff --git a/src/test/test_util.c b/src/test/test_util.c
index 7ab54e1..2c4f804 100644
--- a/src/test/test_util.c
+++ b/src/test/test_util.c
@@ -802,7 +802,7 @@ test_util_strmisc(void)
 {
   char buf[1024];
   int i;
-  char *cp;
+  char *cp, *cp_tmp;
 
   /* Test strl operations */
   test_eq(5, strlcpy(buf, "Hello", 0));
@@ -1005,20 +1005,20 @@ test_util_strmisc(void)
   /* Test strndup and memdup */
   {
     const char *s = "abcdefghijklmnopqrstuvwxyz";
-    cp = tor_strndup(s, 30);
-    test_streq(cp, s); /* same string, */
-    test_neq_ptr(cp, s); /* but different pointers. */
-    tor_free(cp);
+    cp_tmp = tor_strndup(s, 30);
+    test_streq(cp_tmp, s); /* same string, */
+    test_neq_ptr(cp_tmp, s); /* but different pointers. */
+    tor_free(cp_tmp);
 
-    cp = tor_strndup(s, 5);
-    test_streq(cp, "abcde");
-    tor_free(cp);
+    cp_tmp = tor_strndup(s, 5);
+    test_streq(cp_tmp, "abcde");
+    tor_free(cp_tmp);
 
     s = "a\0b\0c\0d\0e\0";
-    cp = tor_memdup(s,10);
-    test_memeq(cp, s, 10); /* same ram, */
-    test_neq_ptr(cp, s); /* but different pointers. */
-    tor_free(cp);
+    cp_tmp = tor_memdup(s,10);
+    test_memeq(cp_tmp, s, 10); /* same ram, */
+    test_neq_ptr(cp_tmp, s); /* but different pointers. */
+    tor_free(cp_tmp);
   }
 
   /* Test str-foo functions */
@@ -1097,7 +1097,7 @@ test_util_strmisc(void)
   tt_int_op(strcmp_len("blah", "", 0),    ==, 0);
 
  done:
-  ;
+  tor_free(cp_tmp);
 }
 
 static void



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits