Revision: 14947
Author: [email protected]
Date: Wed Jun 5 02:41:24 2013
Log: Free PerThreadAssertData when possible to avoid memory leak.
[email protected]
BUG=246567
Review URL: https://chromiumcodereview.appspot.com/16093024
http://code.google.com/p/v8/source/detail?r=14947
Modified:
/branches/bleeding_edge/src/assert-scope.h
=======================================
--- /branches/bleeding_edge/src/assert-scope.h Mon Jun 3 08:32:22 2013
+++ /branches/bleeding_edge/src/assert-scope.h Wed Jun 5 02:41:24 2013
@@ -48,7 +48,7 @@
#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;
}
@@ -61,9 +61,13 @@
bool get(PerThreadAssertType type) const {
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 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 @@
}
static Thread::LocalStorageKey thread_local_key;
+ PerThreadAssertData* data_;
friend class Isolate;
#endif // DEBUG
};
@@ -98,12 +118,11 @@
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); }
--
--
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.