Revision: 15106
Author:   [email protected]
Date:     Thu Jun 13 00:47:42 2013
Log:      Fix memory leak in assert scopes.

[email protected]
BUG=246567

Review URL: https://chromiumcodereview.appspot.com/15709020
http://code.google.com/p/v8/source/detail?r=15106

Modified:
 /branches/bleeding_edge/src/assert-scope.h

=======================================
--- /branches/bleeding_edge/src/assert-scope.h  Wed Jun  5 02:41:24 2013
+++ /branches/bleeding_edge/src/assert-scope.h  Thu Jun 13 00:47:42 2013
@@ -79,7 +79,11 @@

  protected:
   PerThreadAssertScopeBase() {
-    data_ = AssertData();
+    data_ = GetAssertData();
+    if (data_ == NULL) {
+      data_ = new PerThreadAssertData();
+      SetThreadLocalData(data_);
+    }
     data_->increment_level();
   }

@@ -89,22 +93,22 @@
       ASSERT(data_->get(static_cast<PerThreadAssertType>(i)));
     }
     delete data_;
-    Thread::SetThreadLocal(thread_local_key, NULL);
+    SetThreadLocalData(NULL);
   }

-  static PerThreadAssertData* AssertData() {
-    PerThreadAssertData* data = reinterpret_cast<PerThreadAssertData*>(
-            Thread::GetThreadLocal(thread_local_key));
-    if (data == NULL) {
-      data = new PerThreadAssertData();
-      Thread::SetThreadLocal(thread_local_key, data);
-    }
-    return data;
+  static PerThreadAssertData* GetAssertData() {
+    return reinterpret_cast<PerThreadAssertData*>(
+        Thread::GetThreadLocal(thread_local_key));
   }

   static Thread::LocalStorageKey thread_local_key;
   PerThreadAssertData* data_;
   friend class Isolate;
+
+ private:
+  static void SetThreadLocalData(PerThreadAssertData* data) {
+    Thread::SetThreadLocal(thread_local_key, data);
+  }
 #endif  // DEBUG
 };

@@ -124,7 +128,10 @@

   ~PerThreadAssertScope() { data_->set(type, old_state_); }

-  static bool IsAllowed() { return AssertData()->get(type); }
+  static bool IsAllowed() {
+    PerThreadAssertData* data = GetAssertData();
+    return data == NULL || data->get(type);
+  }

  private:
   bool old_state_;

--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
--- You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to