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

Unified Diff: base/memory/scoped_vector_unittest.cc

Issue 1365893002: Fix LifeCycleWatcher in ScopedVectorTest to not be referenced after being destructed. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 3 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: base/memory/scoped_vector_unittest.cc
diff --git a/base/memory/scoped_vector_unittest.cc b/base/memory/scoped_vector_unittest.cc
index 220cfb04687c74fbf13f950bd52b757cf340ca44..4dee9c9004e93e3c0a0ddfdaa58ec6d9079439fa 100644
--- a/base/memory/scoped_vector_unittest.cc
+++ b/base/memory/scoped_vector_unittest.cc
@@ -24,7 +24,8 @@ class LifeCycleObject {
};
~LifeCycleObject() {
- observer_->OnLifeCycleDestroy(this);
+ if (observer_)
+ observer_->OnLifeCycleDestroy(this);
}
private:
@@ -35,6 +36,10 @@ class LifeCycleObject {
observer_->OnLifeCycleConstruct(this);
}
+ void DisconnectObserver() {
+ observer_ = nullptr;
+ }
+
Observer* observer_;
DISALLOW_COPY_AND_ASSIGN(LifeCycleObject);
@@ -62,7 +67,13 @@ enum LifeCycleState {
class LifeCycleWatcher : public LifeCycleObject::Observer {
public:
LifeCycleWatcher() : life_cycle_state_(LC_INITIAL) {}
- ~LifeCycleWatcher() override {}
+ ~LifeCycleWatcher() override {
+ // Stop watching the watched object. Without this, the object's destructor
danakj 2015/09/24 17:43:51 Alternatively, you could just keep the watcher ali
Anand Mistry (off Chromium) 2015/09/24 21:56:27 The two tests that fail are WeakClear and InsertRa
+ // will call into OnLifeCycleDestroy when destructed, which happens after
+ // this destructor has finished running.
+ if (constructed_life_cycle_object_)
+ constructed_life_cycle_object_->DisconnectObserver();
+ }
// Assert INITIAL -> CONSTRUCTED and no LifeCycleObject associated with this
// LifeCycleWatcher.
« 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