summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
authorLei Zhang <thestig@chromium.org>2015-09-22 19:15:49 -0700
committerLei Zhang <thestig@chromium.org>2015-09-22 19:15:49 -0700
commitcef2a9c51bee4b987fc813013d45dad6535a9a46 (patch)
tree6bb1cb91c327f9664ab510bca617205b638f1c6d /core
parent3b4382a847b5a7439a3107512dbe54c317108579 (diff)
downloadpdfium-cef2a9c51bee4b987fc813013d45dad6535a9a46.tar.xz
Change nonstd::unique_ptr to take a custom deleter.
Code is mostly stolen from Chromium's scoped_ptr. - Add unit tests. - Use this to fix a leak. BUG=chromium:531408 R=jyasskin@chromium.org, tsepez@chromium.org Review URL: https://codereview.chromium.org/1351383004 .
Diffstat (limited to 'core')
-rw-r--r--core/include/fxcrt/fx_basic.h8
-rw-r--r--core/src/fpdfapi/fpdf_parser/fpdf_parser_parser.cpp7
2 files changed, 12 insertions, 3 deletions
diff --git a/core/include/fxcrt/fx_basic.h b/core/include/fxcrt/fx_basic.h
index bc3d81200f..3e556f5439 100644
--- a/core/include/fxcrt/fx_basic.h
+++ b/core/include/fxcrt/fx_basic.h
@@ -947,6 +947,13 @@ class CFX_AutoRestorer {
T m_OldValue;
};
+// Used with nonstd::unique_ptr to Release() objects that can't be deleted.
+template <class T>
+struct ReleaseDeleter {
+ inline void operator()(T* ptr) const { ptr->Release(); }
+};
+
+// TODO(thestig) Remove in favor of nonstd::unique_ptr.
template <class T>
class CFX_SmartPointer {
public:
@@ -959,6 +966,7 @@ class CFX_SmartPointer {
protected:
T* m_pObj;
};
+
#define FX_DATALIST_LENGTH 1024
template <size_t unit>
class CFX_SortListArray {
diff --git a/core/src/fpdfapi/fpdf_parser/fpdf_parser_parser.cpp b/core/src/fpdfapi/fpdf_parser/fpdf_parser_parser.cpp
index ff14a984bd..7482f0b8e4 100644
--- a/core/src/fpdfapi/fpdf_parser/fpdf_parser_parser.cpp
+++ b/core/src/fpdfapi/fpdf_parser/fpdf_parser_parser.cpp
@@ -2376,8 +2376,9 @@ CPDF_Object* CPDF_SyntaxParser::GetObjectByStrict(
continue;
}
key = PDF_NameDecode(key);
- CPDF_Object* pObj = GetObject(pObjList, objnum, gennum);
- if (pObj == NULL) {
+ nonstd::unique_ptr<CPDF_Object, ReleaseDeleter<CPDF_Object>> obj(
+ GetObject(pObjList, objnum, gennum));
+ if (!obj) {
if (pDict) {
pDict->Release();
}
@@ -2394,7 +2395,7 @@ CPDF_Object* CPDF_SyntaxParser::GetObjectByStrict(
}
if (key.GetLength() > 1) {
pDict->AddValue(CFX_ByteStringC(key.c_str() + 1, key.GetLength() - 1),
- pObj);
+ obj.release());
}
}
if (pContext) {