]> git.ipfire.org Git - thirdparty/moment.git/commitdiff
[bugfix] Avoid memory leak in updateLocale
authorAsh Searle <ash@hexmen.com>
Sun, 15 Apr 2018 10:40:42 +0000 (11:40 +0100)
committerIskren Chernev <iskren.chernev@gmail.com>
Sun, 26 Apr 2020 23:32:01 +0000 (02:32 +0300)
src/lib/locale/locales.js

index e873af8990b7d1de86b7a3360f8d1d8ebeebd538..438e6ba3dbb301516aeebc24db5dcf9ad0b417f5 100644 (file)
@@ -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);