summaryrefslogtreecommitdiff
path: root/xfa/fxfa/fm2js/xfa_fmparse.cpp
diff options
context:
space:
mode:
authornpm <npm@chromium.org>2016-11-23 14:47:35 -0800
committerCommit bot <commit-bot@chromium.org>2016-11-23 14:47:35 -0800
commit4e847e36fe013bcfddf71c79221887a308b9fadb (patch)
tree6a029f6d2d19ba3f8ff919f10f031e1c46867a3f /xfa/fxfa/fm2js/xfa_fmparse.cpp
parent9fd0c630ea2225fc544949d88d1bf63acc43112e (diff)
downloadpdfium-4e847e36fe013bcfddf71c79221887a308b9fadb.tar.xz
More unique_ptrs in CXFA_FMParse::ParseForeachExpression and avoid leak
Commit a31098417852bdf13e693a6e0913e0706cf94098 accidentally caused a leak. Replaced pointers with unique_ptr to prevent this from happening. BUG=664891 Review-Url: https://codereview.chromium.org/2528543003
Diffstat (limited to 'xfa/fxfa/fm2js/xfa_fmparse.cpp')
-rw-r--r--xfa/fxfa/fm2js/xfa_fmparse.cpp26
1 files changed, 10 insertions, 16 deletions
diff --git a/xfa/fxfa/fm2js/xfa_fmparse.cpp b/xfa/fxfa/fm2js/xfa_fmparse.cpp
index a383b2e04a..36663fce2d 100644
--- a/xfa/fxfa/fm2js/xfa_fmparse.cpp
+++ b/xfa/fxfa/fm2js/xfa_fmparse.cpp
@@ -8,6 +8,9 @@
#include <memory>
#include <utility>
+#include <vector>
+
+#include "third_party/base/ptr_util.h"
CXFA_FMParse::CXFA_FMParse() : m_pToken(nullptr), m_pErrorInfo(0) {}
@@ -989,7 +992,7 @@ CXFA_FMExpression* CXFA_FMParse::ParseForExpression() {
CXFA_FMExpression* CXFA_FMParse::ParseForeachExpression() {
std::unique_ptr<CXFA_FMExpression> e;
CFX_WideStringC wsIdentifier;
- std::unique_ptr<CFX_ArrayTemplate<CXFA_FMSimpleExpression*>> pAccessors;
+ std::vector<std::unique_ptr<CXFA_FMSimpleExpression>> pAccessors;
std::unique_ptr<CXFA_FMExpression> pList;
uint32_t line = m_pToken->m_uLinenum;
NextToken();
@@ -1008,17 +1011,13 @@ CXFA_FMExpression* CXFA_FMParse::ParseForeachExpression() {
ws_TempString.c_str());
NextToken();
} else {
- pAccessors.reset(new CFX_ArrayTemplate<CXFA_FMSimpleExpression*>());
while (m_pToken->m_type != TOKrparen) {
CXFA_FMSimpleExpression* s = ParseSimpleExpression();
- if (s) {
- pAccessors->Add(s);
- }
- if (m_pToken->m_type == TOKcomma) {
- NextToken();
- } else {
+ if (s)
+ pAccessors.push_back(pdfium::WrapUnique<CXFA_FMSimpleExpression>(s));
+ if (m_pToken->m_type != TOKcomma)
break;
- }
+ NextToken();
}
Check(TOKrparen);
}
@@ -1026,13 +1025,8 @@ CXFA_FMExpression* CXFA_FMParse::ParseForeachExpression() {
pList.reset(ParseBlockExpression());
Check(TOKendfor);
if (m_pErrorInfo->message.IsEmpty()) {
- e.reset(new CXFA_FMForeachExpression(
- line, wsIdentifier, pAccessors.release(), pList.release()));
- } else {
- if (pAccessors) {
- for (int i = 0; i < pAccessors->GetSize(); ++i)
- delete static_cast<CXFA_FMSimpleExpression*>(pAccessors->GetAt(i));
- }
+ e = pdfium::MakeUnique<CXFA_FMForeachExpression>(
+ line, wsIdentifier, std::move(pAccessors), pList.release());
}
return e.release();
}