Index: core/fpdfapi/font/fpdf_font_cid.cpp |
diff --git a/core/fpdfapi/font/fpdf_font_cid.cpp b/core/fpdfapi/font/fpdf_font_cid.cpp |
index 010c94ced2862b8d2ef19828632c327266f56369..386eec334a1e11831fef8864755fd7a39fef7bb8 100644 |
--- a/core/fpdfapi/font/fpdf_font_cid.cpp |
+++ b/core/fpdfapi/font/fpdf_font_cid.cpp |
@@ -6,6 +6,9 @@ |
#include "core/fpdfapi/font/font_int.h" |
+#include <memory> |
+#include <utility> |
+ |
#include "core/fpdfapi/cmaps/cmap_int.h" |
#include "core/fpdfapi/cpdf_modulemgr.h" |
#include "core/fpdfapi/font/ttgsubtable.h" |
@@ -278,37 +281,34 @@ int GetCharSizeImpl(uint32_t charcode, |
} // namespace |
-CPDF_CMapManager::CPDF_CMapManager() { |
- FXSYS_memset(m_CID2UnicodeMaps, 0, sizeof m_CID2UnicodeMaps); |
-} |
-CPDF_CMapManager::~CPDF_CMapManager() { |
- for (const auto& pair : m_CMaps) { |
- delete pair.second; |
- } |
- m_CMaps.clear(); |
- for (size_t i = 0; i < FX_ArraySize(m_CID2UnicodeMaps); ++i) { |
- delete m_CID2UnicodeMaps[i]; |
- } |
-} |
-CPDF_CMap* CPDF_CMapManager::GetPredefinedCMap(const CFX_ByteString& name, |
- bool bPromptCJK) { |
+CPDF_CMapManager::CPDF_CMapManager() {} |
+ |
+CPDF_CMapManager::~CPDF_CMapManager() {} |
+ |
+CFX_MaybeOwned<CPDF_CMap> CPDF_CMapManager::GetPredefinedCMap( |
+ const CFX_ByteString& name, |
+ bool bPromptCJK) { |
auto it = m_CMaps.find(name); |
- if (it != m_CMaps.end()) { |
- return it->second; |
- } |
- CPDF_CMap* pCMap = LoadPredefinedCMap(name, bPromptCJK); |
- if (!name.IsEmpty()) { |
Tom Sepez
2017/01/18 23:16:25
note: leak here if name is empty and we don't stic
|
- m_CMaps[name] = pCMap; |
- } |
- return pCMap; |
+ if (it != m_CMaps.end()) |
+ return CFX_MaybeOwned<CPDF_CMap>(it->second.get()); // Unowned. |
+ |
+ std::unique_ptr<CPDF_CMap> pCMap = LoadPredefinedCMap(name, bPromptCJK); |
+ if (name.IsEmpty()) |
+ return CFX_MaybeOwned<CPDF_CMap>(std::move(pCMap)); // Owned. |
+ |
+ CPDF_CMap* pUnowned = pCMap.get(); |
+ m_CMaps[name] = std::move(pCMap); |
+ return CFX_MaybeOwned<CPDF_CMap>(pUnowned); // Unowned. |
} |
-CPDF_CMap* CPDF_CMapManager::LoadPredefinedCMap(const CFX_ByteString& name, |
- bool bPromptCJK) { |
- CPDF_CMap* pCMap = new CPDF_CMap; |
+ |
+std::unique_ptr<CPDF_CMap> CPDF_CMapManager::LoadPredefinedCMap( |
+ const CFX_ByteString& name, |
+ bool bPromptCJK) { |
+ auto pCMap = pdfium::MakeUnique<CPDF_CMap>(); |
const FX_CHAR* pname = name.c_str(); |
- if (*pname == '/') { |
+ if (*pname == '/') |
pname++; |
- } |
+ |
pCMap->LoadPredefined(this, pname, bPromptCJK); |
return pCMap; |
} |
@@ -317,11 +317,14 @@ CPDF_CID2UnicodeMap* CPDF_CMapManager::GetCID2UnicodeMap(CIDSet charset, |
bool bPromptCJK) { |
if (!m_CID2UnicodeMaps[charset]) |
m_CID2UnicodeMaps[charset] = LoadCID2UnicodeMap(charset, bPromptCJK); |
- return m_CID2UnicodeMaps[charset]; |
+ |
+ return m_CID2UnicodeMaps[charset].get(); |
} |
-CPDF_CID2UnicodeMap* CPDF_CMapManager::LoadCID2UnicodeMap(CIDSet charset, |
- bool bPromptCJK) { |
- CPDF_CID2UnicodeMap* pMap = new CPDF_CID2UnicodeMap(); |
+ |
+std::unique_ptr<CPDF_CID2UnicodeMap> CPDF_CMapManager::LoadCID2UnicodeMap( |
+ CIDSet charset, |
+ bool bPromptCJK) { |
+ auto pMap = pdfium::MakeUnique<CPDF_CID2UnicodeMap>(); |
pMap->Load(this, charset, bPromptCJK); |
return pMap; |
} |