From 593bf02c8b65cdea1d77c6800a9af57e1c6cb08b Mon Sep 17 00:00:00 2001 From: Ashod Nakashian Date: Mon, 28 Jan 2019 20:48:01 -0500 Subject: sd: LOK: avoid caching pointers and leaking Change-Id: I68163bc30b0655b11dec34bdcc750b495b93365a Reviewed-on: https://gerrit.libreoffice.org/68265 Reviewed-by: Andras Timar Tested-by: Andras Timar (cherry picked from commit da70e562087b6016aeaffadedc4ce66eaf370919) Reviewed-on: https://gerrit.libreoffice.org/76284 Tested-by: Jenkins Reviewed-by: Noel Grandin --- sd/inc/CustomAnimationPreset.hxx | 2 +- sd/source/core/CustomAnimationPreset.cxx | 19 ++++++++----------- 2 files changed, 9 insertions(+), 12 deletions(-) (limited to 'sd') diff --git a/sd/inc/CustomAnimationPreset.hxx b/sd/inc/CustomAnimationPreset.hxx index 57669734014b..ad21b7a00d4a 100644 --- a/sd/inc/CustomAnimationPreset.hxx +++ b/sd/inc/CustomAnimationPreset.hxx @@ -129,7 +129,7 @@ private: PresetCategoryList maMiscPresets; //! Maps per-language the animation presets. - SAL_DLLPRIVATE static std::map mpCustomAnimationPresetsMap; + SAL_DLLPRIVATE static std::map mPresetsMap; }; diff --git a/sd/source/core/CustomAnimationPreset.cxx b/sd/source/core/CustomAnimationPreset.cxx index 4c02acc25d6c..9ac326fe668c 100644 --- a/sd/source/core/CustomAnimationPreset.cxx +++ b/sd/source/core/CustomAnimationPreset.cxx @@ -524,7 +524,7 @@ void CustomAnimationPresets::changePresetSubType( const CustomAnimationEffectPtr } } -std::map CustomAnimationPresets::mpCustomAnimationPresetsMap; +std::map CustomAnimationPresets::mPresetsMap; const CustomAnimationPresets& CustomAnimationPresets::getCustomAnimationPresets() { @@ -535,16 +535,13 @@ const CustomAnimationPresets& CustomAnimationPresets::getCustomAnimationPresets( : SvtSysLocaleOptions().GetLanguageTag().getLanguage(); SolarMutexGuard aGuard; - const auto it = mpCustomAnimationPresetsMap.find(aLang); - if (it != mpCustomAnimationPresetsMap.end()) - return *it->second; - - // Note: we are invoked recursively(!), so we must set the instance pointer - // in the cache map before we importResources, lest we get in infinite loop. - sd::CustomAnimationPresets* pCustomAnimationPresets = new sd::CustomAnimationPresets(); - mpCustomAnimationPresetsMap[aLang] = pCustomAnimationPresets; - pCustomAnimationPresets->importResources(); - return *pCustomAnimationPresets; + const auto it = mPresetsMap.find(aLang); + if (it != mPresetsMap.end()) + return it->second; + + CustomAnimationPresets& rPresets = mPresetsMap[aLang]; + rPresets.importResources(); + return rPresets; } Reference< XAnimationNode > CustomAnimationPresets::getRandomPreset( sal_Int16 nPresetClass ) const -- cgit