You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by rm...@apache.org on 2022/11/19 19:41:46 UTC

[logging-log4cxx] branch next_stable updated: Fix the memory leaks from the testing framework

This is an automated email from the ASF dual-hosted git repository.

rmiddleton pushed a commit to branch next_stable
in repository https://gitbox.apache.org/repos/asf/logging-log4cxx.git


The following commit(s) were added to refs/heads/next_stable by this push:
     new ccf2ff28 Fix the memory leaks from the testing framework
ccf2ff28 is described below

commit ccf2ff28f2e86bb3313d668533ba0de7f8f2f2ee
Author: Robert Middleton <ro...@rm5248.com>
AuthorDate: Sat Nov 5 11:31:32 2022 -0400

    Fix the memory leaks from the testing framework
---
 src/test/cpp/abts.cpp | 29 +++++++++++++++--------------
 src/test/cpp/abts.h   |  2 +-
 2 files changed, 16 insertions(+), 15 deletions(-)

diff --git a/src/test/cpp/abts.cpp b/src/test/cpp/abts.cpp
index 1efb8344..e0e0e286 100644
--- a/src/test/cpp/abts.cpp
+++ b/src/test/cpp/abts.cpp
@@ -148,8 +148,10 @@ abts_suite* abts_add_suite(abts_suite* suite, const char* suite_name_full)
 
 	if (p)
 	{
-		subsuite->name = (const char*) memcpy(calloc(p - suite_name + 1, 1),
-				suite_name, p - suite_name);
+//		subsuite->name = (const char*) memcpy(calloc(p - suite_name + 1, 1),
+//				suite_name, p - suite_name);
+		int length = p - suite_name + 1;
+		subsuite->name = std::string( suite_name, length );
 	}
 	else
 	{
@@ -158,7 +160,7 @@ abts_suite* abts_add_suite(abts_suite* suite, const char* suite_name_full)
 
 	if (list_tests)
 	{
-		fprintf(stdout, "%s\n", subsuite->name);
+		fprintf(stdout, "%s\n", subsuite->name.c_str());
 	}
 
 	subsuite->not_run = 0;
@@ -175,14 +177,14 @@ abts_suite* abts_add_suite(abts_suite* suite, const char* suite_name_full)
 		suite->tail = subsuite;
 	}
 
-	if (!should_test_run(subsuite->name))
+	if (!should_test_run(subsuite->name.c_str()))
 	{
 		subsuite->not_run = 1;
 		return suite;
 	}
 
 	reset_status();
-	fprintf(stdout, "%-20s:  ", subsuite->name);
+	fprintf(stdout, "%-20s:  ", subsuite->name.c_str());
 	update_status();
 	fflush(stdout);
 
@@ -194,7 +196,7 @@ void abts_run_test(abts_suite* ts, const char* name, test_func f, void* value)
 	abts_case tc;
 	sub_suite* ss;
 
-	if (!should_test_run(ts->tail->name))
+	if (!should_test_run(ts->tail->name.c_str()))
 	{
 		return;
 	}
@@ -600,16 +602,15 @@ int main(int argc, const char* const argv[])
 		//    clean up suite
 		//
 		// We're about to exit, who cares about memory leaks?
-//		sub_suite* next;
+		sub_suite* next;
 
-//		for (sub_suite* head = suite->head; head != NULL; head = next)
-//		{
-//			next = head->next;
-//			delete[] head->name;
-//			delete head;
-//		}
+		for (sub_suite* head = suite->head; head != NULL; head = next)
+		{
+			next = head->next;
+			delete head;
+		}
 
-//		delete suite;
+		delete suite;
 	}
 
 	return rv;
diff --git a/src/test/cpp/abts.h b/src/test/cpp/abts.h
index c3fb6f6b..7560c738 100644
--- a/src/test/cpp/abts.h
+++ b/src/test/cpp/abts.h
@@ -40,7 +40,7 @@
 
 struct sub_suite
 {
-	const char* name;
+	std::string name;
 	int num_test;
 	std::vector<const char*> failed;
 	int not_run;