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

Unified Diff: third_party/WebKit/Source/wtf/RefPtr.h

Issue 2696703008: Adds RefPtr::leakRef method to allow raw pointers that prevent destruct. (Closed)
Patch Set: Added deref in RefPtrTest.LeakRef to avoid memory leak. Created 3 years, 10 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: third_party/WebKit/Source/wtf/RefPtr.h
diff --git a/third_party/WebKit/Source/wtf/RefPtr.h b/third_party/WebKit/Source/wtf/RefPtr.h
index c6b28fa72555e1e21bf744db89a969596127da1d..6dca0985aac0db86f39a9e777cc190ba2989d457 100644
--- a/third_party/WebKit/Source/wtf/RefPtr.h
+++ b/third_party/WebKit/Source/wtf/RefPtr.h
@@ -70,7 +70,7 @@ class RefPtr {
ALWAYS_INLINE ~RefPtr() { derefIfNotNull(m_ptr); }
ALWAYS_INLINE T* get() const { return m_ptr; }
-
+ T* leakRef() WARN_UNUSED_RESULT;
void clear();
PassRefPtr<T> release() {
PassRefPtr<T> tmp = adoptRef(m_ptr);
@@ -111,6 +111,13 @@ inline RefPtr<T>::RefPtr(const PassRefPtr<U>& o,
: m_ptr(o.leakRef()) {}
template <typename T>
+inline T* RefPtr<T>::leakRef() {
+ T* ptr = m_ptr;
+ m_ptr = nullptr;
+ return ptr;
+}
+
+template <typename T>
inline void RefPtr<T>::clear() {
T* ptr = m_ptr;
m_ptr = nullptr;

Powered by Google App Engine
This is Rietveld 408576698