From: Ash Searle Date: Sun, 15 Apr 2018 10:40:42 +0000 (+0100) Subject: [bugfix] Avoid memory leak in updateLocale X-Git-Tag: 2.25.0~31^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e360fb4a4038bf93f4e457b63980d43f15688f20;p=thirdparty%2Fmoment.git [bugfix] Avoid memory leak in updateLocale --- diff --git a/src/lib/locale/locales.js b/src/lib/locale/locales.js index e873af899..438e6ba3d 100644 --- a/src/lib/locale/locales.js +++ b/src/lib/locale/locales.js @@ -177,15 +177,21 @@ export function updateLocale(name, config) { var locale, tmpLocale, parentConfig = baseConfig; - // MERGE - tmpLocale = loadLocale(name); - if (tmpLocale != null) { - parentConfig = tmpLocale._config; + + if (locales[name] != null && locales[name].parentLocale != null) { + // Update existing child locale in-place to avoid memory-leaks + locales[name].set(mergeConfigs(locales[name]._config, config)); + } else { + // MERGE + tmpLocale = loadLocale(name); + if (tmpLocale != null) { + parentConfig = tmpLocale._config; + } + config = mergeConfigs(parentConfig, config); + locale = new Locale(config); + locale.parentLocale = locales[name]; + locales[name] = locale; } - config = mergeConfigs(parentConfig, config); - locale = new Locale(config); - locale.parentLocale = locales[name]; - locales[name] = locale; // backwards compat for now: also set the locale getSetGlobalLocale(name);