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

Unified Diff: src/assert-scope.h

Issue 15709020: Fix memory leak in assert scopes. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: addressed comments Created 7 years, 6 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 | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/assert-scope.h
diff --git a/src/assert-scope.h b/src/assert-scope.h
index e2ec542a7708230af2bee1fc4f4840218afd967e..9ccb56bef0a3f7641792d18f41d9abd865882b3a 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<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:
+ void SetThreadLocalData(PerThreadAssertData* data) {
Sven Panne 2013/06/13 06:11:38 nit: add "static"
+ 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_;
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698