From 21e954b59fcef1b84fdcdb9ae337e2d4c060b19e Mon Sep 17 00:00:00 2001 From: Dan Sinclair Date: Wed, 8 Feb 2017 10:05:05 -0500 Subject: 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 Commit-Queue: dsinclair --- xfa/fde/css/cfde_cssstyleselector.cpp | 37 ++++++++++++++--------------------- 1 file changed, 15 insertions(+), 22 deletions(-) (limited to 'xfa/fde/css/cfde_cssstyleselector.cpp') diff --git a/xfa/fde/css/cfde_cssstyleselector.cpp b/xfa/fde/css/cfde_cssstyleselector.cpp index fa17f7b20b..1319a64a84 100644 --- a/xfa/fde/css/cfde_cssstyleselector.cpp +++ b/xfa/fde/css/cfde_cssstyleselector.cpp @@ -105,10 +105,8 @@ void CFDE_CSSStyleSelector::ComputeStyle( if (!styleString.IsEmpty()) AppendInlineStyle(pDecl.get(), styleString); if (!alignString.IsEmpty()) { - FDE_CSSPropertyArgs args; - args.pStringCache = nullptr; - args.pProperty = FDE_GetCSSPropertyByEnum(FDE_CSSProperty::TextAlign); - pDecl->AddProperty(&args, alignString.c_str(), alignString.GetLength()); + pDecl->AddProperty(FDE_GetCSSPropertyByEnum(FDE_CSSProperty::TextAlign), + alignString.AsStringC()); } } ApplyDeclarations(declArray, pDecl.get(), pDest); @@ -130,7 +128,7 @@ void CFDE_CSSStyleSelector::ApplyDeclarations( for (auto& prop : normals) ApplyProperty(prop->eProperty, prop->pValue.Get(), pComputedStyle); for (auto& prop : customs) - pComputedStyle->AddCustomStyle(prop->pwsName, prop->pwsValue); + pComputedStyle->AddCustomStyle(*prop); for (auto& prop : importants) ApplyProperty(prop->eProperty, prop->pValue.Get(), pComputedStyle); } @@ -159,28 +157,23 @@ void CFDE_CSSStyleSelector::AppendInlineStyle(CFDE_CSSDeclaration* pDecl, return; int32_t iLen2 = 0; - const FX_WCHAR* psz2; - FDE_CSSPropertyArgs args; - args.pStringCache = nullptr; - args.pProperty = nullptr; + const FDE_CSSPropertyTable* table = nullptr; CFX_WideString wsName; while (1) { FDE_CSSSyntaxStatus eStatus = pSyntax->DoSyntaxParse(); if (eStatus == FDE_CSSSyntaxStatus::PropertyName) { - psz2 = pSyntax->GetCurrentString(iLen2); - args.pProperty = FDE_GetCSSPropertyByName(CFX_WideStringC(psz2, iLen2)); - if (!args.pProperty) - wsName = CFX_WideStringC(psz2, iLen2); + CFX_WideStringC strValue = pSyntax->GetCurrentString(); + table = FDE_GetCSSPropertyByName(strValue); + if (!table) + wsName = CFX_WideString(strValue); } else if (eStatus == FDE_CSSSyntaxStatus::PropertyValue) { - if (args.pProperty) { - psz2 = pSyntax->GetCurrentString(iLen2); - if (iLen2 > 0) - pDecl->AddProperty(&args, psz2, iLen2); - } else if (iLen2 > 0) { - psz2 = pSyntax->GetCurrentString(iLen2); - if (iLen2 > 0) { - pDecl->AddProperty(&args, wsName.c_str(), wsName.GetLength(), psz2, - iLen2); + if (table || iLen2 > 0) { + CFX_WideStringC strValue = pSyntax->GetCurrentString(); + if (!strValue.IsEmpty()) { + if (table) + pDecl->AddProperty(table, strValue); + else if (iLen2 > 0) + pDecl->AddProperty(wsName, CFX_WideString(strValue)); } } } else { -- cgit v1.2.3