diff options
author | Dan Sinclair <dsinclair@chromium.org> | 2017-02-08 10:05:05 -0500 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2017-02-09 15:55:20 +0000 |
commit | 21e954b59fcef1b84fdcdb9ae337e2d4c060b19e (patch) | |
tree | 2053cd0a8b0d4c1bb6903db3aa6f753a23afedcf /xfa/fde/css/cfde_cssstylesheet.cpp | |
parent | 1b08df18300bbc67dabd12fb35ab6ce1732a1024 (diff) | |
download | pdfium-21e954b59fcef1b84fdcdb9ae337e2d4c060b19e.tar.xz |
Remove CopyToLocal from CFDE_CSSDeclaration
This CL removes the CopyToLocal method and creates CFX_WideString's directly.
This fixes several memory leaks as the CopyToLocal strings were not cleaned
up correctly.
Change-Id: Ie5ba4cdc4d713cd0b8e3fb85e02f27dc09f38af1
Reviewed-on: https://pdfium-review.googlesource.com/2553
Reviewed-by: Tom Sepez <tsepez@chromium.org>
Commit-Queue: dsinclair <dsinclair@chromium.org>
Diffstat (limited to 'xfa/fde/css/cfde_cssstylesheet.cpp')
-rw-r--r-- | xfa/fde/css/cfde_cssstylesheet.cpp | 51 |
1 files changed, 24 insertions, 27 deletions
diff --git a/xfa/fde/css/cfde_cssstylesheet.cpp b/xfa/fde/css/cfde_cssstylesheet.cpp index b05e837f95..c8bf70ec23 100644 --- a/xfa/fde/css/cfde_cssstylesheet.cpp +++ b/xfa/fde/css/cfde_cssstylesheet.cpp @@ -63,45 +63,40 @@ FDE_CSSSyntaxStatus CFDE_CSSStyleSheet::LoadStyleRule( std::vector<std::unique_ptr<CFDE_CSSSelector>> selectors; CFDE_CSSStyleRule* pStyleRule = nullptr; - const FX_WCHAR* pszValue = nullptr; int32_t iValueLen = 0; - FDE_CSSPropertyArgs propertyArgs; - propertyArgs.pStringCache = &m_StringCache; - propertyArgs.pProperty = nullptr; + const FDE_CSSPropertyTable* propertyTable = nullptr; CFX_WideString wsName; while (1) { switch (pSyntax->DoSyntaxParse()) { case FDE_CSSSyntaxStatus::Selector: { - pszValue = pSyntax->GetCurrentString(iValueLen); - auto pSelector = CFDE_CSSSelector::FromString(pszValue, iValueLen); + CFX_WideStringC strValue = pSyntax->GetCurrentString(); + auto pSelector = CFDE_CSSSelector::FromString(strValue); if (pSelector) selectors.push_back(std::move(pSelector)); break; } - case FDE_CSSSyntaxStatus::PropertyName: - pszValue = pSyntax->GetCurrentString(iValueLen); - propertyArgs.pProperty = - FDE_GetCSSPropertyByName(CFX_WideStringC(pszValue, iValueLen)); - if (!propertyArgs.pProperty) - wsName = CFX_WideStringC(pszValue, iValueLen); + case FDE_CSSSyntaxStatus::PropertyName: { + CFX_WideStringC strValue = pSyntax->GetCurrentString(); + propertyTable = FDE_GetCSSPropertyByName(strValue); + if (!propertyTable) + wsName = CFX_WideString(strValue); break; - case FDE_CSSSyntaxStatus::PropertyValue: - if (propertyArgs.pProperty) { - pszValue = pSyntax->GetCurrentString(iValueLen); - if (iValueLen > 0) { - pStyleRule->GetDeclaration()->AddProperty(&propertyArgs, pszValue, - iValueLen); - } - } else if (iValueLen > 0) { - pszValue = pSyntax->GetCurrentString(iValueLen); - if (iValueLen > 0) { - pStyleRule->GetDeclaration()->AddProperty( - &propertyArgs, wsName.c_str(), wsName.GetLength(), pszValue, - iValueLen); + } + case FDE_CSSSyntaxStatus::PropertyValue: { + if (propertyTable || iValueLen > 0) { + CFX_WideStringC strValue = pSyntax->GetCurrentString(); + auto decl = pStyleRule->GetDeclaration(); + if (!strValue.IsEmpty()) { + if (propertyTable) { + decl->AddProperty(propertyTable, strValue); + } else { + decl->AddProperty(wsName, CFX_WideString(strValue)); + } } } break; - case FDE_CSSSyntaxStatus::DeclOpen: + } + case FDE_CSSSyntaxStatus::DeclOpen: { if (!pStyleRule && !selectors.empty()) { auto rule = pdfium::MakeUnique<CFDE_CSSStyleRule>(); pStyleRule = rule.get(); @@ -112,12 +107,14 @@ FDE_CSSSyntaxStatus CFDE_CSSStyleSheet::LoadStyleRule( return FDE_CSSSyntaxStatus::None; } break; - case FDE_CSSSyntaxStatus::DeclClose: + } + case FDE_CSSSyntaxStatus::DeclClose: { if (pStyleRule && pStyleRule->GetDeclaration()->empty()) { ruleArray->pop_back(); pStyleRule = nullptr; } return FDE_CSSSyntaxStatus::None; + } case FDE_CSSSyntaxStatus::EOS: return FDE_CSSSyntaxStatus::EOS; case FDE_CSSSyntaxStatus::Error: |