lucy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nwelln...@apache.org
Subject [lucy-commits] [2/3] git commit: refs/heads/cfc-tests - Fix memory leaks in CFC tests
Date Sun, 03 Feb 2013 20:00:46 GMT
Fix memory leaks in CFC tests


Project: http://git-wip-us.apache.org/repos/asf/lucy/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucy/commit/6d023482
Tree: http://git-wip-us.apache.org/repos/asf/lucy/tree/6d023482
Diff: http://git-wip-us.apache.org/repos/asf/lucy/diff/6d023482

Branch: refs/heads/cfc-tests
Commit: 6d02348260e52b5d8e99186fd30bc60833b214fa
Parents: 93f0c4e
Author: Nick Wellnhofer <wellnhofer@aevum.de>
Authored: Sun Feb 3 20:58:27 2013 +0100
Committer: Nick Wellnhofer <wellnhofer@aevum.de>
Committed: Sun Feb 3 20:58:27 2013 +0100

----------------------------------------------------------------------
 clownfish/compiler/src/CFCTestClass.c       |    7 +++++++
 clownfish/compiler/src/CFCTestDocuComment.c |    1 +
 clownfish/compiler/src/CFCTestFile.c        |   16 ++++++++++------
 clownfish/compiler/src/CFCTestHierarchy.c   |   19 +++++++++++++------
 clownfish/compiler/src/CFCTestUtil.c        |    2 ++
 5 files changed, 33 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucy/blob/6d023482/clownfish/compiler/src/CFCTestClass.c
----------------------------------------------------------------------
diff --git a/clownfish/compiler/src/CFCTestClass.c b/clownfish/compiler/src/CFCTestClass.c
index f3f3f96..80f008a 100644
--- a/clownfish/compiler/src/CFCTestClass.c
+++ b/clownfish/compiler/src/CFCTestClass.c
@@ -157,6 +157,9 @@ S_run_tests(CFCTest *test) {
         CFCVariable **fresh_member_vars = CFCClass_fresh_member_vars(foo);
         OK(test, fresh_member_vars[0] == thing, "fresh_member_vars[0]");
         OK(test, fresh_member_vars[1] == NULL, "fresh_member_vars[1]");
+
+        FREEMEM(fresh_methods);
+        FREEMEM(fresh_member_vars);
     }
 
     {
@@ -172,11 +175,14 @@ S_run_tests(CFCTest *test) {
 
         CFCVariable **inert_vars = CFCClass_inert_vars(foo_jr);
         OK(test, inert_vars[0] == NULL, "inert_vars[0]");
+
+        FREEMEM(fresh_member_vars);
     }
 
     {
         CFCMethod **fresh_methods = CFCClass_fresh_methods(final_foo);
         OK(test, fresh_methods[0] == NULL, "fresh_methods[0]");
+        FREEMEM(fresh_methods);
     }
 
     {
@@ -190,6 +196,7 @@ S_run_tests(CFCTest *test) {
         OK(test, ladder[1] == foo_jr, "ladder[1]");
         OK(test, ladder[2] == final_foo, "ladder[2]");
         OK(test, ladder[3] == NULL, "ladder[3]");
+        FREEMEM(ladder);
     }
 
     {

http://git-wip-us.apache.org/repos/asf/lucy/blob/6d023482/clownfish/compiler/src/CFCTestDocuComment.c
----------------------------------------------------------------------
diff --git a/clownfish/compiler/src/CFCTestDocuComment.c b/clownfish/compiler/src/CFCTestDocuComment.c
index a5121cd..dba5f3c 100644
--- a/clownfish/compiler/src/CFCTestDocuComment.c
+++ b/clownfish/compiler/src/CFCTestDocuComment.c
@@ -102,5 +102,6 @@ S_run_tests(CFCTest *test) {
     STR_EQ(test, retval, retval_expect, "retval");
 
     CFCBase_decref((CFCBase*)docucomment);
+    CFCBase_decref((CFCBase*)parser);
 }
 

http://git-wip-us.apache.org/repos/asf/lucy/blob/6d023482/clownfish/compiler/src/CFCTestFile.c
----------------------------------------------------------------------
diff --git a/clownfish/compiler/src/CFCTestFile.c b/clownfish/compiler/src/CFCTestFile.c
index dbd2c89..7d45b59 100644
--- a/clownfish/compiler/src/CFCTestFile.c
+++ b/clownfish/compiler/src/CFCTestFile.c
@@ -24,6 +24,7 @@
 #include "CFCParser.h"
 #include "CFCTest.h"
 #include "CFCType.h"
+#include "CFCUtil.h"
 #include "CFCVariable.h"
 
 static void
@@ -74,12 +75,15 @@ S_run_tests(CFCTest *test) {
     "Stuff" CHY_DIR_SEP \
     "Thing"
 
-        STR_EQ(test, CFCFile_cfh_path(file, "path/to"),
-               PATH_TO_STUFF_THING ".cfh", "cfh_path" );
-        STR_EQ(test, CFCFile_c_path(file, "path/to"),
-               PATH_TO_STUFF_THING ".c", "c_path" );
-        STR_EQ(test, CFCFile_h_path(file, "path/to"),
-               PATH_TO_STUFF_THING ".h", "h_path" );
+        char *cfh_path = CFCFile_cfh_path(file, "path/to");
+        STR_EQ(test, cfh_path, PATH_TO_STUFF_THING ".cfh", "cfh_path");
+        FREEMEM(cfh_path);
+        char *c_path = CFCFile_c_path(file, "path/to");
+        STR_EQ(test, c_path, PATH_TO_STUFF_THING ".c", "c_path");
+        FREEMEM(c_path);
+        char *h_path = CFCFile_h_path(file, "path/to");
+        STR_EQ(test, h_path, PATH_TO_STUFF_THING ".h", "h_path");
+        FREEMEM(h_path);
 
         CFCClass **classes = CFCFile_classes(file);
         OK(test, classes[0] != NULL && classes[1] == NULL,

http://git-wip-us.apache.org/repos/asf/lucy/blob/6d023482/clownfish/compiler/src/CFCTestHierarchy.c
----------------------------------------------------------------------
diff --git a/clownfish/compiler/src/CFCTestHierarchy.c b/clownfish/compiler/src/CFCTestHierarchy.c
index 90a586b..3f46c78 100644
--- a/clownfish/compiler/src/CFCTestHierarchy.c
+++ b/clownfish/compiler/src/CFCTestHierarchy.c
@@ -108,11 +108,14 @@ S_run_basic_tests(CFCTest *test) {
     }
     OK(test, files[3] == NULL, "recursed and found all three files");
 
-    CFCClass **ordered_classes = CFCHierarchy_ordered_classes(hierarchy);
-    OK(test, ordered_classes[0] != NULL, "ordered_classes[0]");
-    OK(test, ordered_classes[1] != NULL, "ordered_classes[1]");
-    OK(test, ordered_classes[2] != NULL, "ordered_classes[2]");
-    OK(test, ordered_classes[3] == NULL, "all classes");
+    {
+        CFCClass **ordered_classes = CFCHierarchy_ordered_classes(hierarchy);
+        OK(test, ordered_classes[0] != NULL, "ordered_classes[0]");
+        OK(test, ordered_classes[1] != NULL, "ordered_classes[1]");
+        OK(test, ordered_classes[2] != NULL, "ordered_classes[2]");
+        OK(test, ordered_classes[3] == NULL, "all classes");
+        FREEMEM(ordered_classes);
+    }
 
     // Generate fake C files, with times set to two seconds ago.
     time_t now       = time(NULL);
@@ -131,7 +134,9 @@ S_run_basic_tests(CFCTest *test) {
         CFCTest_set_file_times(h_path, past_time);
     }
 
-    CFCTest_set_file_times(CFCFile_cfh_path(animal, T_CFSOURCE), now);
+    char *cfh_path = CFCFile_cfh_path(animal, T_CFSOURCE);
+    CFCTest_set_file_times(cfh_path, now);
+    FREEMEM(cfh_path);
 
     CFCHierarchy_propagate_modified(hierarchy, 0);
 
@@ -186,6 +191,7 @@ S_run_include_tests(CFCTest *test) {
         STR_EQ(test, CFCClass_get_class_name(CFCClass_get_parent(rottweiler)),
                "Animal::Dog", "parent of included class");
 
+        FREEMEM(classes);
         CFCBase_decref((CFCBase*)hierarchy);
         CFCClass_clear_registry();
     }
@@ -213,6 +219,7 @@ S_run_include_tests(CFCTest *test) {
         STR_EQ(test, CFCClass_get_class_name(CFCClass_get_parent(rottweiler)),
                "Animal::Dog", "parent of class from second source");
 
+        FREEMEM(classes);
         CFCBase_decref((CFCBase*)hierarchy);
         CFCClass_clear_registry();
     }

http://git-wip-us.apache.org/repos/asf/lucy/blob/6d023482/clownfish/compiler/src/CFCTestUtil.c
----------------------------------------------------------------------
diff --git a/clownfish/compiler/src/CFCTestUtil.c b/clownfish/compiler/src/CFCTestUtil.c
index f985d0d..fd431e3 100644
--- a/clownfish/compiler/src/CFCTestUtil.c
+++ b/clownfish/compiler/src/CFCTestUtil.c
@@ -62,6 +62,7 @@ S_run_string_tests(CFCTest *test) {
     str = CFCUtil_strdup(" \r\n\tabc \r\n\tdef \r\n\t");
     CFCUtil_trim_whitespace(str);
     STR_EQ(test, str, "abc \r\n\tdef", "trim_whitespace");
+    FREEMEM(str);
 }
 
 static void
@@ -89,6 +90,7 @@ S_run_file_tests(CFCTest *test) {
         char *content = CFCUtil_slurp_text(foo_txt, &content_len);
         INT_EQ(test, content_len, 3, "slurp_text len");
         OK(test, memcmp(content, "foo", 3) == 0, "slurp_text content");
+        FREEMEM(content);
     }
 
     {


Mime
View raw message