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

Unified Diff: src/assert-scope.h

Issue 16093024: Free PerThreadAssertData when possible to avoid memory leak. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: 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 d32d680d1c18410f5c9bef37c52401e6c133bb26..e2ec542a7708230af2bee1fc4f4840218afd967e 100644
--- a/src/assert-scope.h
+++ b/src/assert-scope.h
@@ -48,7 +48,7 @@ enum PerThreadAssertType {
#ifdef DEBUG
class PerThreadAssertData {
public:
- PerThreadAssertData() {
+ PerThreadAssertData() : nesting_level_(0) {
for (int i = 0; i < LAST_PER_THREAD_ASSERT_TYPE; i++) {
assert_states_[i] = true;
}
@@ -62,8 +62,12 @@ class PerThreadAssertData {
return assert_states_[type];
}
+ void increment_level() { ++nesting_level_; }
+ bool decrement_level() { return --nesting_level_ == 0; }
+
private:
bool assert_states_[LAST_PER_THREAD_ASSERT_TYPE];
+ int nesting_level_;
DISALLOW_COPY_AND_ASSIGN(PerThreadAssertData);
};
@@ -72,7 +76,22 @@ class PerThreadAssertData {
class PerThreadAssertScopeBase {
#ifdef DEBUG
+
protected:
+ PerThreadAssertScopeBase() {
+ data_ = AssertData();
+ data_->increment_level();
+ }
+
+ ~PerThreadAssertScopeBase() {
+ if (!data_->decrement_level()) return;
+ for (int i = 0; i < LAST_PER_THREAD_ASSERT_TYPE; i++) {
+ ASSERT(data_->get(static_cast<PerThreadAssertType>(i)));
+ }
+ delete data_;
+ Thread::SetThreadLocal(thread_local_key, NULL);
+ }
+
static PerThreadAssertData* AssertData() {
PerThreadAssertData* data = reinterpret_cast<PerThreadAssertData*>(
Thread::GetThreadLocal(thread_local_key));
@@ -84,6 +103,7 @@ class PerThreadAssertScopeBase {
}
static Thread::LocalStorageKey thread_local_key;
+ PerThreadAssertData* data_;
friend class Isolate;
#endif // DEBUG
};
@@ -98,12 +118,11 @@ class PerThreadAssertScope : public PerThreadAssertScopeBase {
static void SetIsAllowed(bool is_allowed) { }
#else
PerThreadAssertScope() {
- PerThreadAssertData* data = AssertData();
- old_state_ = data->get(type);
- data->set(type, allow);
+ old_state_ = data_->get(type);
+ data_->set(type, allow);
}
- ~PerThreadAssertScope() { AssertData()->set(type, old_state_); }
+ ~PerThreadAssertScope() { data_->set(type, old_state_); }
static bool IsAllowed() { return AssertData()->get(type); }
« 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