Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(872)

Unified Diff: runtime/vm/log_test.cc

Issue 2651013002: Fix memory leaks in cc/Log_* tests (Closed)
Patch Set: Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « runtime/tests/vm/vm.status ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/vm/log_test.cc
diff --git a/runtime/vm/log_test.cc b/runtime/vm/log_test.cc
index 84ef8559a829b3b9958c7f0daee997bfddd8708b..aa95f094660d5761e6d55d06979e0dcb4e88f561 100644
--- a/runtime/vm/log_test.cc
+++ b/runtime/vm/log_test.cc
@@ -16,7 +16,7 @@
namespace dart {
-static const char* test_output_;
+static const char* test_output_ = NULL;
static void TestPrinter(const char* format, ...) {
// Measure.
va_list args;
@@ -31,7 +31,10 @@ static void TestPrinter(const char* format, ...) {
OS::VSNPrint(buffer, (len + 1), format, args2);
va_end(args2);
- // Leaks buffer.
+ if (test_output_ != NULL) {
+ free(const_cast<char*>(test_output_));
+ test_output_ = NULL;
+ }
test_output_ = buffer;
}
@@ -42,6 +45,13 @@ class LogTestHelper : public AllStatic {
ASSERT(printer != NULL);
log->printer_ = printer;
}
+
+ static void FreeTestOutput() {
+ if (test_output_ != NULL) {
Vyacheslav Egorov (Google) 2017/01/24 16:10:51 No need to check if it is not NULL - free(NULL) is
+ free(const_cast<char*>(test_output_));
+ test_output_ = NULL;
+ }
+ }
};
@@ -54,6 +64,7 @@ TEST_CASE(Log_Macro) {
EXPECT_STREQ("Hello World", test_output_);
THR_Print("SingleArgument");
EXPECT_STREQ("SingleArgument", test_output_);
+ LogTestHelper::FreeTestOutput();
}
@@ -64,6 +75,9 @@ TEST_CASE(Log_Basic) {
EXPECT_EQ(reinterpret_cast<const char*>(NULL), test_output_);
log->Print("Hello %s", "World");
EXPECT_STREQ("Hello World", test_output_);
+
+ delete log;
+ LogTestHelper::FreeTestOutput();
}
@@ -84,6 +98,8 @@ TEST_CASE(Log_Block) {
EXPECT_STREQ("BANANA", test_output_);
}
EXPECT_STREQ("APPLE", test_output_);
+ delete log;
+ LogTestHelper::FreeTestOutput();
}
} // namespace dart
« no previous file with comments | « runtime/tests/vm/vm.status ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698