segfault fixed when bad SCI environment variable is setted when using call_scilab. 47/17447/3
Cedric Delamarre [Thu, 12 Nov 2015 10:31:42 +0000 (11:31 +0100)]
Change-Id: I7af8b9587f4c354a148a947245702d6715ec3f07

scilab/modules/core/src/cpp/InitScilab.cpp
scilab/modules/core/src/cpp/tasks.cpp
scilab/modules/functions_manager/includes/functions_manager.h
scilab/modules/functions_manager/src/cpp/functions_manager.cpp

index 8fb71f0..1775c52 100644 (file)
@@ -263,7 +263,12 @@ int StartScilabEngine(ScilabEngineInfo* _pSEI)
     C2F(setprlev) (&pause);
 
     //load gateways
-    LoadModules();
+    if (LoadModules() == false)
+    {
+        //clear opened files
+        FileManager::destroy();
+        return 1;
+    }
 
     //variables are needed by loadModules but must be in SCOPE_CONSOLE under protection
     //remove (W)SCI/SCIHOME/HOME/TMPDIR
index f4835bf..912024e 100644 (file)
@@ -231,13 +231,23 @@ int execScilabStartTask(bool _bSerialize)
     stSCI += SCILAB_START;
 
     ThreadManagement::LockParser();
-    parse.parseFile(stSCI, L"");
+    try
+    {
+        parse.parseFile(stSCI, L"");
+    }
+    catch (const ast::InternalError& ie)
+    {
+        scilabWrite(ie.what());
+        ThreadManagement::UnlockParser();
+        return 1;
+    }
+
     if (parse.getExitStatus() != Parser::Succeded)
     {
         scilabWriteW(parse.getErrorMessage());
         scilabWriteW(L"Failed to parse scilab.start");
         ThreadManagement::UnlockParser();
-        return 0;
+        return 1;
     }
     ThreadManagement::UnlockParser();
 
@@ -261,13 +271,23 @@ int execScilabQuitTask(bool _bSerialize)
     stSCI += SCILAB_QUIT;
 
     ThreadManagement::LockParser();
-    parse.parseFile(stSCI, L"");
+    try
+    {
+        parse.parseFile(stSCI, L"");
+    }
+    catch (const ast::InternalError& ie)
+    {
+        scilabWrite(ie.what());
+        ThreadManagement::UnlockParser();
+        return 1;
+    }
+
     if (parse.getExitStatus() != Parser::Succeded)
     {
         scilabWriteW(parse.getErrorMessage());
         scilabWriteW(L"Failed to parse scilab.quit");
         ThreadManagement::UnlockParser();
-        return 0;
+        return 1;
     }
     ThreadManagement::UnlockParser();
 
index 31a2c90..3019ea2 100644 (file)
@@ -16,8 +16,8 @@
 #define __FUNCMANAGER_H__
 
 
-FUNCMAN_IMEXP void LoadModules();
+FUNCMAN_IMEXP bool LoadModules();
 FUNCMAN_IMEXP void UnloadModules();
 FUNCMAN_IMEXP void EndModules();
 FUNCMAN_IMEXP void destroyfunctionManagerInstance(void);
-#endif /* !__FUNCMANAGER_H__ */
\ No newline at end of file
+#endif /* !__FUNCMANAGER_H__ */
index 7bebdd2..bf15cdf 100644 (file)
@@ -17,13 +17,16 @@ extern "C"
 #include "functions_manager.h"
 }
 
-void LoadModules()
+bool LoadModules()
 {
     FuncManager* pFM = FuncManager::getInstance();
-    if (pFM)
+    if (pFM == NULL)
     {
-        pFM->LoadModules();
+        return false;
     }
+
+    pFM->LoadModules();
+    return true;
 }
 
 void EndModules()
@@ -47,4 +50,4 @@ void UnloadModules()
 void destroyfunctionManagerInstance(void)
 {
     FuncManager::destroyInstance();
-}
\ No newline at end of file
+}