summaryrefslogtreecommitdiff
path: root/core/fxcrt
diff options
context:
space:
mode:
authortsepez <tsepez@chromium.org>2017-01-03 15:58:33 -0800
committerCommit bot <commit-bot@chromium.org>2017-01-03 15:58:33 -0800
commit4741b291f462c0c4a5de4abf1653c3b3c87b613a (patch)
treeeece57648dfd0bd49ce653be9b90b65271d083e6 /core/fxcrt
parentd654d7854951e0ed3589fcc34617c7ca593d9e86 (diff)
downloadpdfium-4741b291f462c0c4a5de4abf1653c3b3c87b613a.tar.xz
Add CFX_RetainPtr Leak() and Unleak() methods
Required to pass pointers across C-APIs. Need this to clean up CPDFXFA_Page and retain ptrs. Review-Url: https://codereview.chromium.org/2583093003
Diffstat (limited to 'core/fxcrt')
-rw-r--r--core/fxcrt/cfx_retain_ptr.h4
-rw-r--r--core/fxcrt/cfx_retain_ptr_unittest.cpp21
2 files changed, 25 insertions, 0 deletions
diff --git a/core/fxcrt/cfx_retain_ptr.h b/core/fxcrt/cfx_retain_ptr.h
index bff1b9691c..1b137d4974 100644
--- a/core/fxcrt/cfx_retain_ptr.h
+++ b/core/fxcrt/cfx_retain_ptr.h
@@ -37,6 +37,10 @@ class CFX_RetainPtr {
T* Get() const { return m_pObj.get(); }
void Swap(CFX_RetainPtr& that) { m_pObj.swap(that.m_pObj); }
+ // TODO(tsepez): temporary scaffolding, to be removed.
+ T* Leak() { return m_pObj.release(); }
+ void Unleak(T* ptr) { m_pObj.reset(ptr); }
+
CFX_RetainPtr& operator=(const CFX_RetainPtr& that) {
if (*this != that)
Reset(that.Get());
diff --git a/core/fxcrt/cfx_retain_ptr_unittest.cpp b/core/fxcrt/cfx_retain_ptr_unittest.cpp
index 692beb82ff..f9a4ecb74f 100644
--- a/core/fxcrt/cfx_retain_ptr_unittest.cpp
+++ b/core/fxcrt/cfx_retain_ptr_unittest.cpp
@@ -128,6 +128,27 @@ TEST(fxcrt, RetainPtrSwap) {
EXPECT_EQ(1, obj2.release_count());
}
+TEST(fxcrt, RetainPtrLeak) {
+ PseudoRetainable obj;
+ PseudoRetainable* leak;
+ {
+ CFX_RetainPtr<PseudoRetainable> ptr(&obj);
+ leak = ptr.Leak();
+ EXPECT_EQ(1, obj.retain_count());
+ EXPECT_EQ(0, obj.release_count());
+ }
+ EXPECT_EQ(1, obj.retain_count());
+ EXPECT_EQ(0, obj.release_count());
+ {
+ CFX_RetainPtr<PseudoRetainable> ptr;
+ ptr.Unleak(leak);
+ EXPECT_EQ(1, obj.retain_count());
+ EXPECT_EQ(0, obj.release_count());
+ }
+ EXPECT_EQ(1, obj.retain_count());
+ EXPECT_EQ(1, obj.release_count());
+}
+
TEST(fxcrt, RetainPtrSwapNull) {
PseudoRetainable obj1;
{