fix crash at startup 59/17259/2
Simon Marchetto [Fri, 25 Sep 2015 09:15:41 +0000 (11:15 +0200)]
Change-Id: I0ccb61e94f0b6d5329eead3fde56edf94e8fc209

scilab/modules/helptools/sci_gateway/cpp/sci_buildDoc.cpp
scilab/modules/localization/includes/setgetlanguage.h
scilab/modules/localization/sci_gateway/cpp/sci_getlanguage.cpp
scilab/modules/localization/src/c/LanguagePreferences_Windows.c
scilab/modules/localization/src/c/setgetlanguage.c

index 68e4296..0e8bf5e 100644 (file)
@@ -105,7 +105,9 @@ extern "C"
 
         if (Rhs < 3)            /* Language not provided */
         {
-            language = wide_string_to_UTF8(getlanguage());
+            wchar_t* l = getlanguage();
+            language = wide_string_to_UTF8(l);
+            free(l);
         }
         else
         {
@@ -128,7 +130,9 @@ extern "C"
 
             if (!isScalar(pvApiCtx, piAddr))
             {
-                language = wide_string_to_UTF8(getlanguage());
+                wchar_t* pwstLang = getlanguage();
+                language = wide_string_to_UTF8(pwstLang);
+                free(pwstLang);
             }
             else
             {
index 4738c3b..2f6c83d 100644 (file)
@@ -29,7 +29,7 @@ BOOL setlanguage(const wchar_t *lang);
  * returns current language
  * @return
  */
-const wchar_t *getlanguage(void);
+wchar_t *getlanguage(void);
 
 /**
  * returns current alias
index ee4bc58..fc62ec0 100644 (file)
@@ -37,7 +37,9 @@ types::Function::ReturnValue sci_getlanguage(types::typed_list &in, int _piRetCo
         return types::Function::Error;
     }
 
-    out.push_back(new types::String(getlanguage()));
+    wchar_t* pwstLang = getlanguage();
+    out.push_back(new types::String(pwstLang));
+    free(pwstLang);
 
     return types::Function::OK;
 }
index c17dcd8..96a55bc 100644 (file)
@@ -187,7 +187,9 @@ static wchar_t *getLanguagePreferencesAllUsers(void)
 /*--------------------------------------------------------------------------*/
 BOOL setLanguagePreferences(void)
 {
-    char *LANGUAGE = wide_string_to_UTF8(getlanguage());
+    wchar_t* pwstLang = getlanguage();
+    char *LANGUAGE = wide_string_to_UTF8(pwstLang);
+    free(pwstLang);
 
     if (LANGUAGE)
     {
index 94d24de..befce65 100644 (file)
@@ -225,9 +225,9 @@ BOOL setlanguage(const wchar_t *lang)
     return FALSE;
 }
 /*--------------------------------------------------------------------------*/
-const wchar_t *getlanguage(void)
+wchar_t *getlanguage(void)
 {
-    return CURRENTLANGUAGESTRING;
+    return os_wcsdup(CURRENTLANGUAGESTRING);
 }
 /*--------------------------------------------------------------------------*/
 int getcurrentlanguagecode(void)
@@ -334,13 +334,14 @@ const wchar_t *getlanguagealias(void)
 /*--------------------------------------------------------------------------*/
 BOOL needtochangelanguage(const wchar_t *language)
 {
-    const wchar_t *currentlanguage = getlanguage();
-
+    wchar_t *currentlanguage = getlanguage();
     if (wcscmp(language, currentlanguage))
     {
+        free(currentlanguage);
         return TRUE;
     }
 
+    free(currentlanguage);
     return FALSE;
 }
 /*--------------------------------------------------------------------------*/