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

Side by Side Diff: base/observer_list_unittest.cc

Issue 7134008: Revert 88151 (see crbug.com/85296) - Fix user-after-free error with ObserverList. The problem is... (Closed) Base URL: svn://svn.chromium.org/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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « base/observer_list.h ('k') | content/browser/renderer_host/render_view_host.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/observer_list.h" 5 #include "base/observer_list.h"
6 #include "base/observer_list_threadsafe.h" 6 #include "base/observer_list_threadsafe.h"
7 7
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/memory/ref_counted.h" 10 #include "base/memory/ref_counted.h"
(...skipping 404 matching lines...) Expand 10 before | Expand all | Expand 10 after
415 AddInClearObserve a(&observer_list); 415 AddInClearObserve a(&observer_list);
416 416
417 observer_list.AddObserver(&a); 417 observer_list.AddObserver(&a);
418 418
419 FOR_EACH_OBSERVER(Foo, observer_list, Observe(1)); 419 FOR_EACH_OBSERVER(Foo, observer_list, Observe(1));
420 EXPECT_TRUE(a.added()); 420 EXPECT_TRUE(a.added());
421 EXPECT_EQ(0, a.adder().total) 421 EXPECT_EQ(0, a.adder().total)
422 << "Adder should not observe, so sum should still be 0."; 422 << "Adder should not observe, so sum should still be 0.";
423 } 423 }
424 424
425 class ListDestructor : public Foo {
426 public:
427 explicit ListDestructor(ObserverList<Foo>* list) : list_(list) {}
428 virtual void Observe(int x) {
429 delete list_;
430 }
431 virtual ~ListDestructor() { }
432 int total;
433 private:
434 ObserverList<Foo>* list_;
435 };
436
437
438 TEST(ObserverListTest, IteratorOutlivesList) {
439 ObserverList<Foo>* observer_list = new ObserverList<Foo>;
440 ListDestructor a(observer_list);
441 observer_list->AddObserver(&a);
442
443 FOR_EACH_OBSERVER(Foo, *observer_list, Observe(0));
444 // If this test fails, there'll be Valgrind errors when this function goes out
445 // of scope.
446 }
447
448 } // namespace 425 } // namespace
OLDNEW
« no previous file with comments | « base/observer_list.h ('k') | content/browser/renderer_host/render_view_host.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698