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

Unified Diff: base/observer_list_unittest.cc

Issue 7127001: Fix user-after-free error with ObserverList. The problem is that if an ObserverListBase::Iterato... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 9 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
Index: base/observer_list_unittest.cc
===================================================================
--- base/observer_list_unittest.cc (revision 87996)
+++ base/observer_list_unittest.cc (working copy)
@@ -422,4 +422,27 @@
<< "Adder should not observe, so sum should still be 0.";
}
+class ListDestructor : public Foo {
+ public:
+ explicit ListDestructor(ObserverList<Foo>* list) : list_(list) {}
+ virtual void Observe(int x) {
+ delete list_;
+ }
+ virtual ~ListDestructor() { }
+ int total;
+ private:
+ ObserverList<Foo>* list_;
+};
+
+
+TEST(ObserverListTest, IteratorOutlivesList) {
+ ObserverList<Foo>* observer_list = new ObserverList<Foo>;
+ ListDestructor a(observer_list);
+ observer_list->AddObserver(&a);
+
+ FOR_EACH_OBSERVER(Foo, *observer_list, Observe(0));
+ // If this test fails, there'll be Valgrind errors when this function goes out
+ // of scope.
+}
+
} // namespace

Powered by Google App Engine
This is Rietveld 408576698