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

Unified Diff: base/memory/scoped_ptr.h

Issue 1356483002: Call reset(nullptr) in scoped_ptr's. (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_ptr.h
diff --git a/base/memory/scoped_ptr.h b/base/memory/scoped_ptr.h
index fb781b0b32ddfd8b47ff3e4a0662ff53b9cd8760..47124d4b6d982a34481916ab5fe1ab4db74d4979 100644
--- a/base/memory/scoped_ptr.h
+++ b/base/memory/scoped_ptr.h
@@ -220,6 +220,12 @@ class scoped_ptr_impl {
// Not using get_deleter() saves one function call in non-optimized
// builds.
static_cast<D&>(data_)(data_.ptr);
+ // Even though |this| should no longer be accessed after destruction,
+ // there may be use-after-free bugs. Setting |data_.ptr| to null should
+ // cause many attempts to dereference |this| to segfault closer to the
+ // source of the use-after-free. Of course, this may not catch issues if
+ // the memory is immediately re-allocated and altered.
+ data_.ptr = nullptr;
danakj 2015/09/21 21:40:52 In libc++ they null the member then call the delet
danakj 2015/09/21 21:43:08 I guess that is because they reset() in the destru
Anand Mistry (off Chromium) 2015/09/22 01:13:53 Since we're in the territory of undefined behaviou
tapted 2015/09/22 02:53:09 (drive-by): the null-before-delete strategy is to
Anand Mistry (off Chromium) 2015/09/22 03:14:15 This is the defined behaviour for unique_ptr::rese
}
}
« 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