From: yangguo@chromium.org Date: Thu, 13 Jun 2013 07:47:42 +0000 (+0000) Subject: Fix memory leak in assert scopes. X-Git-Tag: upstream/4.7.83~13871 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=28db1d0ebdd340cc3c96874dd4ac38c9cbea1b24;p=platform%2Fupstream%2Fv8.git Fix memory leak in assert scopes. R=svenpanne@chromium.org BUG=246567 Review URL: https://chromiumcodereview.appspot.com/15709020 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@15106 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- diff --git a/src/assert-scope.h b/src/assert-scope.h index e2ec542..13adbd0 100644 --- a/src/assert-scope.h +++ b/src/assert-scope.h @@ -79,7 +79,11 @@ class PerThreadAssertScopeBase { protected: PerThreadAssertScopeBase() { - data_ = AssertData(); + data_ = GetAssertData(); + if (data_ == NULL) { + data_ = new PerThreadAssertData(); + SetThreadLocalData(data_); + } data_->increment_level(); } @@ -89,22 +93,22 @@ class PerThreadAssertScopeBase { ASSERT(data_->get(static_cast(i))); } delete data_; - Thread::SetThreadLocal(thread_local_key, NULL); + SetThreadLocalData(NULL); } - static PerThreadAssertData* AssertData() { - PerThreadAssertData* data = reinterpret_cast( - 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( + 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 @@ class PerThreadAssertScope : public PerThreadAssertScopeBase { ~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_;