test/hotspot/gtest/logging/logTestFixture.cpp
changeset 49182 bd1bfa4e563f
parent 49171 6ecca4a9c75f
child 49360 886acec3b4c6
--- a/test/hotspot/gtest/logging/logTestFixture.cpp	Wed Feb 28 10:37:02 2018 +0100
+++ b/test/hotspot/gtest/logging/logTestFixture.cpp	Wed Feb 28 12:05:02 2018 +0100
@@ -31,7 +31,7 @@
 #include "unittest.hpp"
 #include "utilities/ostream.hpp"
 
-LogTestFixture::LogTestFixture() {
+LogTestFixture::LogTestFixture() : _configuration_snapshot(NULL), _n_snapshots(0) {
   // Set up TestLogFileName to include PID, testcase name and test name
   int ret = jio_snprintf(_filename, sizeof(_filename), "testlog.pid%d.%s.%s.log",
                          os::current_process_id(),
@@ -45,6 +45,7 @@
 
 LogTestFixture::~LogTestFixture() {
   restore_config();
+  clear_snapshot();
   delete_file(TestLogFileName);
 }
 
@@ -65,6 +66,7 @@
 }
 
 void LogTestFixture::snapshot_config() {
+  clear_snapshot();
   _n_snapshots = LogConfiguration::_n_outputs;
   _configuration_snapshot = NEW_C_HEAP_ARRAY(char*, _n_snapshots, mtLogging);
   for (size_t i = 0; i < _n_snapshots; i++) {
@@ -103,3 +105,16 @@
     set_log_config(name, selection, decorators, options != NULL ? options : "");
   }
 }
+
+void LogTestFixture::clear_snapshot() {
+  if (_configuration_snapshot == NULL) {
+    return;
+  }
+  assert(_n_snapshots > 0, "non-null array should have at least 1 element");
+  for (size_t i = 0; i < _n_snapshots; i++) {
+    os::free(_configuration_snapshot[i]);
+  }
+  FREE_C_HEAP_ARRAY(char*, _configuration_snapshot);
+  _configuration_snapshot = NULL;
+  _n_snapshots = 0;
+}