changeset 4601:1ed2314952c8

8011161: NMT: Memory leak when encountering out of memory error while initializing memory snapshot Summary: Fix memory leaks when NMT fails to initialize snapshot and worker thread Reviewed-by: dcubed, ccheung, rdurbin
author zgu
date Fri, 12 Apr 2013 11:26:55 -0400
parents 3e88170d8be2
children 0c00fe85302b
files src/share/vm/services/memTracker.cpp
diffstat 1 files changed, 9 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/vm/services/memTracker.cpp	Thu Apr 11 22:44:42 2013 -0700
+++ b/src/share/vm/services/memTracker.cpp	Fri Apr 12 11:26:55 2013 -0400
@@ -127,12 +127,15 @@
   assert(_state == NMT_bootstrapping_multi_thread, "wrong state");
 
   _snapshot = new (std::nothrow)MemSnapshot();
-  if (_snapshot != NULL && !_snapshot->out_of_memory()) {
-    if (start_worker()) {
+  if (_snapshot != NULL) {
+    if (!_snapshot->out_of_memory() && start_worker()) {
       _state = NMT_started;
       NMT_track_callsite = (_tracking_level == NMT_detail && can_walk_stack());
       return;
     }
+
+    delete _snapshot;
+    _snapshot = NULL;
   }
 
   // fail to start native memory tracking, shut it down
@@ -544,7 +547,10 @@
   assert(_worker_thread == NULL, "Just Check");
   _worker_thread = new (std::nothrow) MemTrackWorker();
   if (_worker_thread == NULL || _worker_thread->has_error()) {
-    shutdown(NMT_initialization);
+    if (_worker_thread != NULL) {
+      delete _worker_thread;
+      _worker_thread = NULL;
+    }
     return false;
   }
   _worker_thread->start();