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

Side by Side Diff: base/memory/scoped_ptr_unittest.cc

Issue 1356483002: Call reset(nullptr) in scoped_ptr's. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase and change to reset(). 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 unified diff | Download patch
« no previous file with comments | « base/memory/scoped_ptr.h ('k') | no next file » | 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/memory/scoped_ptr.h" 5 #include "base/memory/scoped_ptr.h"
6 6
7 #include <sstream> 7 #include <sstream>
8 8
9 #include "base/basictypes.h" 9 #include "base/basictypes.h"
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 697 matching lines...) Expand 10 before | Expand all | Expand 10 after
708 StructA* a = new StructA; 708 StructA* a = new StructA;
709 a->b.reset(new StructB); 709 a->b.reset(new StructB);
710 a->b->a.reset(a); 710 a->b->a.reset(a);
711 711
712 // Break the cycle by calling reset(). This will cause |a| (and hence, |a.b|) 712 // Break the cycle by calling reset(). This will cause |a| (and hence, |a.b|)
713 // to be deleted before the call to reset() returns. This tests that the 713 // to be deleted before the call to reset() returns. This tests that the
714 // implementation of scoped_ptr::reset() doesn't access |this| after it 714 // implementation of scoped_ptr::reset() doesn't access |this| after it
715 // deletes the underlying pointer. This behaviour is consistent with the 715 // deletes the underlying pointer. This behaviour is consistent with the
716 // definition of unique_ptr::reset in C++11. 716 // definition of unique_ptr::reset in C++11.
717 a->b.reset(); 717 a->b.reset();
718
719 // Go again, but this time, break the cycle by invoking |a|'s destructor. This
720 // tests that the implementation of ~scoped_ptr doesn't infinitely recurse
721 // into the destructors of |a| and |a.b|. Note, deleting |a| instead will
Peter Kasting 2015/09/23 20:35:49 Nit: a.b -> a->b
Anand Mistry (off Chromium) 2015/09/23 23:06:34 Done.
722 // cause |a| to be double-free'd because |a.b| owns |a| and deletes it via its
723 // destructor.
Peter Kasting 2015/09/23 20:35:49 Nit: Maybe change this last sentence to the follow
danakj 2015/09/23 20:38:10 I think I prefer the original for a unit test comm
Anand Mistry (off Chromium) 2015/09/23 23:06:34 danakj: Do you mean what I wrote, or what pkasting
724 a = new StructA;
725 a->b.reset(new StructB);
726 a->b->a.reset(a);
727 a->~StructA();
718 } 728 }
OLDNEW
« no previous file with comments | « base/memory/scoped_ptr.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698