Scicos: fix SIGSEGV and memleaks after 62afc99d 21/20821/2
Clément DAVID [Thu, 7 Feb 2019 16:52:29 +0000 (17:52 +0100)]
Change-Id: I43a7368253e5cd46ee16bce227b6321234f46f74

scilab/modules/scicos/sci_gateway/cpp/sci_model2blk.cpp
scilab/modules/scicos/sci_gateway/cpp/sci_scicosim.cpp
scilab/modules/xcos/tests/nonreg_tests/bug_12384.unix.dia.ref

index 769a91a..af23b1e 100644 (file)
@@ -253,6 +253,7 @@ types::Function::ReturnValue sci_model2blk(types::typed_list &in, int _iRetCount
         wchar_t* w_str = funStr->get(0);
         char* c_str = wide_string_to_UTF8(w_str);
         void* f = funnum2(c_str); // Search associated function number of function name
+        FREE(c_str);
         // Block is defined by a C or Fortran function
         if (f != nullptr)
         {
index d92ac94..fbacea1 100644 (file)
@@ -1017,9 +1017,9 @@ types::Function::ReturnValue sci_scicosim(types::typed_list &in, int _iRetCount,
         il_state->killMe();
         il_tcur->DecreaseRef();
         il_tcur->killMe();
+        delete[] il_sim_labptr;
         il_sim->DecreaseRef();
         il_sim->killMe();
-        delete[] il_sim_labptr;
         return types::Function::Error;
     }
     for (int i = 0; i < il_sim_lab->getSize(); ++i)
@@ -1036,10 +1036,10 @@ types::Function::ReturnValue sci_scicosim(types::typed_list &in, int _iRetCount,
         il_state->killMe();
         il_tcur->DecreaseRef();
         il_tcur->killMe();
-        il_sim->DecreaseRef();
-        il_sim->killMe();
         delete[] il_sim_labptr;
         delete_strings(l_sim_lab, il_sim_lab->getSize());
+        il_sim->DecreaseRef();
+        il_sim->killMe();
         return types::Function::Error;
     }
     types::Double* il_sim_modptr_input = il_sim_input->get(32)->getAs<types::Double>();
@@ -1056,10 +1056,10 @@ types::Function::ReturnValue sci_scicosim(types::typed_list &in, int _iRetCount,
         il_state->killMe();
         il_tcur->DecreaseRef();
         il_tcur->killMe();
-        il_sim->DecreaseRef();
-        il_sim->killMe();
         delete[] il_sim_labptr;
         delete_strings(l_sim_lab, il_sim_lab->getSize());
+        il_sim->DecreaseRef();
+        il_sim->killMe();
         return types::Function::Error;
     }
     types::String* il_sim_uid_input = il_sim_input->get(33)->getAs<types::String>();
@@ -1077,10 +1077,10 @@ types::Function::ReturnValue sci_scicosim(types::typed_list &in, int _iRetCount,
         il_state->killMe();
         il_tcur->DecreaseRef();
         il_tcur->killMe();
-        il_sim->DecreaseRef();
-        il_sim->killMe();
         delete[] il_sim_labptr;
         delete_strings(l_sim_lab, il_sim_lab->getSize());
+        il_sim->DecreaseRef();
+        il_sim->killMe();
         return types::Function::Error;
     }
     char** l_sim_uid;
@@ -1095,11 +1095,11 @@ types::Function::ReturnValue sci_scicosim(types::typed_list &in, int _iRetCount,
         il_state->killMe();
         il_tcur->DecreaseRef();
         il_tcur->killMe();
-        il_sim->DecreaseRef();
-        il_sim->killMe();
         delete[] il_sim_labptr;
         delete_strings(l_sim_lab, il_sim_lab->getSize());
         delete[] il_sim_uidptr;
+        il_sim->DecreaseRef();
+        il_sim->killMe();
         return types::Function::Error;
     }
     for (int i = 0; i < il_sim_uid->getSize(); ++i)
@@ -1118,12 +1118,12 @@ types::Function::ReturnValue sci_scicosim(types::typed_list &in, int _iRetCount,
         il_state->killMe();
         il_tcur->DecreaseRef();
         il_tcur->killMe();
-        il_sim->DecreaseRef();
-        il_sim->killMe();
         delete[] il_sim_labptr;
         delete_strings(l_sim_lab, il_sim_lab->getSize());
         delete[] il_sim_uidptr;
         delete_strings(l_sim_uid, il_sim_uid->getSize());
+        il_sim->DecreaseRef();
+        il_sim->killMe();
         return types::Function::Error;
     }
     types::String* il_str = in[4]->getAs<types::String>();
@@ -1134,12 +1134,12 @@ types::Function::ReturnValue sci_scicosim(types::typed_list &in, int _iRetCount,
         il_state->killMe();
         il_tcur->DecreaseRef();
         il_tcur->killMe();
-        il_sim->DecreaseRef();
-        il_sim->killMe();
         delete[] il_sim_labptr;
         delete_strings(l_sim_lab, il_sim_lab->getSize());
         delete[] il_sim_uidptr;
         delete_strings(l_sim_uid, il_sim_uid->getSize());
+        il_sim->DecreaseRef();
+        il_sim->killMe();
         return types::Function::Error;
     }
 
@@ -1177,12 +1177,12 @@ types::Function::ReturnValue sci_scicosim(types::typed_list &in, int _iRetCount,
         il_state->killMe();
         il_tcur->DecreaseRef();
         il_tcur->killMe();
-        il_sim->DecreaseRef();
-        il_sim->killMe();
         delete[] il_sim_labptr;
         delete_strings(l_sim_lab, il_sim_lab->getSize());
         delete[] il_sim_uidptr;
         delete_strings(l_sim_uid, il_sim_uid->getSize());
+        il_sim->DecreaseRef();
+        il_sim->killMe();
         return types::Function::Error;
     }
 
@@ -1196,12 +1196,12 @@ types::Function::ReturnValue sci_scicosim(types::typed_list &in, int _iRetCount,
         il_state->killMe();
         il_tcur->DecreaseRef();
         il_tcur->killMe();
-        il_sim->DecreaseRef();
-        il_sim->killMe();
         delete[] il_sim_labptr;
         delete_strings(l_sim_lab, il_sim_lab->getSize());
         delete[] il_sim_uidptr;
         delete_strings(l_sim_uid, il_sim_uid->getSize());
+        il_sim->DecreaseRef();
+        il_sim->killMe();
         return types::Function::Error;
     }
     types::Double* il_tol = in[5]->getAs<types::Double>();
@@ -1213,12 +1213,12 @@ types::Function::ReturnValue sci_scicosim(types::typed_list &in, int _iRetCount,
         il_state->killMe();
         il_tcur->DecreaseRef();
         il_tcur->killMe();
-        il_sim->DecreaseRef();
-        il_sim->killMe();
         delete[] il_sim_labptr;
         delete_strings(l_sim_lab, il_sim_lab->getSize());
         delete[] il_sim_uidptr;
         delete_strings(l_sim_uid, il_sim_uid->getSize());
+        il_sim->DecreaseRef();
+        il_sim->killMe();
         return types::Function::Error;
     }
 
@@ -1306,12 +1306,12 @@ types::Function::ReturnValue sci_scicosim(types::typed_list &in, int _iRetCount,
         il_state->killMe();
         il_tcur->DecreaseRef();
         il_tcur->killMe();
-        il_sim->DecreaseRef();
-        il_sim->killMe();
         delete[] il_sim_labptr;
         delete_strings(l_sim_lab, il_sim_lab->getSize());
         delete[] il_sim_uidptr;
         delete_strings(l_sim_uid, il_sim_uid->getSize());
+        il_sim->DecreaseRef();
+        il_sim->killMe();
         return types::Function::Error;
     }
 
@@ -1331,12 +1331,12 @@ types::Function::ReturnValue sci_scicosim(types::typed_list &in, int _iRetCount,
         il_state->killMe();
         il_tcur->DecreaseRef();
         il_tcur->killMe();
-        il_sim->DecreaseRef();
-        il_sim->killMe();
         delete[] il_sim_labptr;
         delete_strings(l_sim_lab, il_sim_lab->getSize());
         delete[] il_sim_uidptr;
         delete_strings(l_sim_uid, il_sim_uid->getSize());
+        il_sim->DecreaseRef();
+        il_sim->killMe();
         return types::Function::Error;
     }
 
@@ -1365,13 +1365,13 @@ types::Function::ReturnValue sci_scicosim(types::typed_list &in, int _iRetCount,
                 il_state->killMe();
                 il_tcur->DecreaseRef();
                 il_tcur->killMe();
-                il_sim->DecreaseRef();
-                il_sim->killMe();
                 delete[] il_sim_labptr;
                 delete_strings(l_sim_lab, il_sim_lab->getSize());
                 delete[] il_sim_uidptr;
                 delete_strings(l_sim_uid, il_sim_uid->getSize());
                 delete[] lfunpt;
+                il_sim->DecreaseRef();
+                il_sim->killMe();
                 return types::Function::Error;
             }
 
@@ -1424,14 +1424,14 @@ types::Function::ReturnValue sci_scicosim(types::typed_list &in, int _iRetCount,
                             il_state->killMe();
                             il_tcur->DecreaseRef();
                             il_tcur->killMe();
-                            il_sim->DecreaseRef();
-                            il_sim->killMe();
                             delete[] il_sim_labptr;
                             delete_strings(l_sim_lab, il_sim_lab->getSize());
                             delete[] il_sim_uidptr;
                             delete_strings(l_sim_uid, il_sim_uid->getSize());
                             delete[] lfunpt;
                             FREE(c_str);
+                            il_sim->DecreaseRef();
+                            il_sim->killMe();
                             return types::Function::Error;
                         }
                     }
@@ -1446,13 +1446,13 @@ types::Function::ReturnValue sci_scicosim(types::typed_list &in, int _iRetCount,
             il_state->killMe();
             il_tcur->DecreaseRef();
             il_tcur->killMe();
-            il_sim->DecreaseRef();
-            il_sim->killMe();
             delete[] il_sim_labptr;
             delete_strings(l_sim_lab, il_sim_lab->getSize());
             delete[] il_sim_uidptr;
             delete_strings(l_sim_uid, il_sim_uid->getSize());
             delete[] lfunpt;
+            il_sim->DecreaseRef();
+            il_sim->killMe();
             return types::Function::Error;
         }
     }
@@ -1477,13 +1477,13 @@ types::Function::ReturnValue sci_scicosim(types::typed_list &in, int _iRetCount,
             il_state->killMe();
             il_tcur->DecreaseRef();
             il_tcur->killMe();
-            il_sim->DecreaseRef();
-            il_sim->killMe();
             delete[] il_sim_labptr;
             delete_strings(l_sim_lab, il_sim_lab->getSize());
             delete[] il_sim_uidptr;
             delete_strings(l_sim_uid, il_sim_uid->getSize());
             delete[] lfunpt;
+            il_sim->DecreaseRef();
+            il_sim->killMe();
             return types::Function::Error;
         }
         // Allocation of 'ozsz'
@@ -1498,14 +1498,14 @@ types::Function::ReturnValue sci_scicosim(types::typed_list &in, int _iRetCount,
             il_state->killMe();
             il_tcur->DecreaseRef();
             il_tcur->killMe();
-            il_sim->DecreaseRef();
-            il_sim->killMe();
             delete[] il_sim_labptr;
             delete_strings(l_sim_lab, il_sim_lab->getSize());
             delete[] il_sim_uidptr;
             delete_strings(l_sim_uid, il_sim_uid->getSize());
             delete[] lfunpt;
             delete[] oz;
+            il_sim->DecreaseRef();
+            il_sim->killMe();
             return types::Function::Error;
         }
         // Allocation of 'oztyp'
@@ -1520,8 +1520,6 @@ types::Function::ReturnValue sci_scicosim(types::typed_list &in, int _iRetCount,
             il_state->killMe();
             il_tcur->DecreaseRef();
             il_tcur->killMe();
-            il_sim->DecreaseRef();
-            il_sim->killMe();
             delete[] il_sim_labptr;
             delete_strings(l_sim_lab, il_sim_lab->getSize());
             delete[] il_sim_uidptr;
@@ -1529,6 +1527,8 @@ types::Function::ReturnValue sci_scicosim(types::typed_list &in, int _iRetCount,
             delete[] lfunpt;
             delete[] oz;
             delete[] ozsz;
+            il_sim->DecreaseRef();
+            il_sim->killMe();
             return types::Function::Error;
         }
 
@@ -1642,8 +1642,6 @@ types::Function::ReturnValue sci_scicosim(types::typed_list &in, int _iRetCount,
             il_state->killMe();
             il_tcur->DecreaseRef();
             il_tcur->killMe();
-            il_sim->DecreaseRef();
-            il_sim->killMe();
             delete[] il_sim_labptr;
             delete_strings(l_sim_lab, il_sim_lab->getSize());
             delete[] il_sim_uidptr;
@@ -1652,6 +1650,8 @@ types::Function::ReturnValue sci_scicosim(types::typed_list &in, int _iRetCount,
             delete[] oz;
             delete[] ozsz;
             delete[] oztyp;
+            il_sim->DecreaseRef();
+            il_sim->killMe();
             return types::Function::Error;
         }
         // Allocation of 'oparsz'
@@ -1666,8 +1666,6 @@ types::Function::ReturnValue sci_scicosim(types::typed_list &in, int _iRetCount,
             il_state->killMe();
             il_tcur->DecreaseRef();
             il_tcur->killMe();
-            il_sim->DecreaseRef();
-            il_sim->killMe();
             delete[] il_sim_labptr;
             delete_strings(l_sim_lab, il_sim_lab->getSize());
             delete[] il_sim_uidptr;
@@ -1677,6 +1675,8 @@ types::Function::ReturnValue sci_scicosim(types::typed_list &in, int _iRetCount,
             delete[] ozsz;
             delete[] oztyp;
             delete[] opar;
+            il_sim->DecreaseRef();
+            il_sim->killMe();
             return types::Function::Error;
         }
         // Allocation of 'opartyp'
@@ -1691,8 +1691,6 @@ types::Function::ReturnValue sci_scicosim(types::typed_list &in, int _iRetCount,
             il_state->killMe();
             il_tcur->DecreaseRef();
             il_tcur->killMe();
-            il_sim->DecreaseRef();
-            il_sim->killMe();
             delete[] il_sim_labptr;
             delete_strings(l_sim_lab, il_sim_lab->getSize());
             delete[] il_sim_uidptr;
@@ -1703,6 +1701,8 @@ types::Function::ReturnValue sci_scicosim(types::typed_list &in, int _iRetCount,
             delete[] oztyp;
             delete[] opar;
             delete[] oparsz;
+            il_sim->DecreaseRef();
+            il_sim->killMe();
             return types::Function::Error;
         }
 
@@ -1736,8 +1736,6 @@ types::Function::ReturnValue sci_scicosim(types::typed_list &in, int _iRetCount,
                             il_state->killMe();
                             il_tcur->DecreaseRef();
                             il_tcur->killMe();
-                            il_sim->DecreaseRef();
-                            il_sim->killMe();
                             delete[] il_sim_labptr;
                             delete_strings(l_sim_lab, il_sim_lab->getSize());
                             delete[] il_sim_uidptr;
@@ -1749,6 +1747,8 @@ types::Function::ReturnValue sci_scicosim(types::typed_list &in, int _iRetCount,
                             delete[] opar;
                             delete[] oparsz;
                             delete[] opartyp;
+                            il_sim->DecreaseRef();
+                            il_sim->killMe();
                             return types::Function::Error;
                         }
                         memcpy(opar[j], oparDouble->get(), oparDouble->getSize() * sizeof(double)); // Real part
@@ -1850,8 +1850,6 @@ types::Function::ReturnValue sci_scicosim(types::typed_list &in, int _iRetCount,
             il_state->killMe();
             il_tcur->DecreaseRef();
             il_tcur->killMe();
-            il_sim->DecreaseRef();
-            il_sim->killMe();
             delete[] il_sim_labptr;
             delete_strings(l_sim_lab, il_sim_lab->getSize());
             delete[] il_sim_uidptr;
@@ -1863,6 +1861,8 @@ types::Function::ReturnValue sci_scicosim(types::typed_list &in, int _iRetCount,
             delete[] opar;
             delete[] oparsz;
             delete[] opartyp;
+            il_sim->DecreaseRef();
+            il_sim->killMe();
             return types::Function::Error;
         }
         // Allocation of 'outtbptrsz'
@@ -1877,8 +1877,6 @@ types::Function::ReturnValue sci_scicosim(types::typed_list &in, int _iRetCount,
             il_state->killMe();
             il_tcur->DecreaseRef();
             il_tcur->killMe();
-            il_sim->DecreaseRef();
-            il_sim->killMe();
             delete[] il_sim_labptr;
             delete_strings(l_sim_lab, il_sim_lab->getSize());
             delete[] il_sim_uidptr;
@@ -1891,6 +1889,8 @@ types::Function::ReturnValue sci_scicosim(types::typed_list &in, int _iRetCount,
             delete[] oparsz;
             delete[] opartyp;
             delete[] outtbptr;
+            il_sim->DecreaseRef();
+            il_sim->killMe();
             return types::Function::Error;
         }
         // Allocation of 'outtbtyp'
@@ -1905,8 +1905,6 @@ types::Function::ReturnValue sci_scicosim(types::typed_list &in, int _iRetCount,
             il_state->killMe();
             il_tcur->DecreaseRef();
             il_tcur->killMe();
-            il_sim->DecreaseRef();
-            il_sim->killMe();
             delete[] il_sim_labptr;
             delete_strings(l_sim_lab, il_sim_lab->getSize());
             delete[] il_sim_uidptr;
@@ -1920,6 +1918,8 @@ types::Function::ReturnValue sci_scicosim(types::typed_list &in, int _iRetCount,
             delete[] opartyp;
             delete[] outtbptr;
             delete[] outtbsz;
+            il_sim->DecreaseRef();
+            il_sim->killMe();
             return types::Function::Error;
         }
 
@@ -1953,8 +1953,6 @@ types::Function::ReturnValue sci_scicosim(types::typed_list &in, int _iRetCount,
                             il_state->killMe();
                             il_tcur->DecreaseRef();
                             il_tcur->killMe();
-                            il_sim->DecreaseRef();
-                            il_sim->killMe();
                             delete[] il_sim_labptr;
                             delete_strings(l_sim_lab, il_sim_lab->getSize());
                             delete[] il_sim_uidptr;
@@ -1968,6 +1966,8 @@ types::Function::ReturnValue sci_scicosim(types::typed_list &in, int _iRetCount,
                             delete[] opartyp;
                             delete[] outtbptr;
                             delete[] outtbsz;
+                            il_sim->DecreaseRef();
+                            il_sim->killMe();
                             return types::Function::Error;
                         }
                         memcpy(outtbptr[j], outtbDouble->get(), outtbDouble->getSize() * sizeof(double)); // Real part
@@ -2039,8 +2039,6 @@ types::Function::ReturnValue sci_scicosim(types::typed_list &in, int _iRetCount,
                     il_state->killMe();
                     il_tcur->DecreaseRef();
                     il_tcur->killMe();
-                    il_sim->DecreaseRef();
-                    il_sim->killMe();
                     delete[] il_sim_labptr;
                     delete_strings(l_sim_lab, il_sim_lab->getSize());
                     delete[] il_sim_uidptr;
@@ -2056,6 +2054,8 @@ types::Function::ReturnValue sci_scicosim(types::typed_list &in, int _iRetCount,
                     delete[] ozsz;
                     delete[] oztyp;
                     FREE(outtb_elem);
+                    il_sim->DecreaseRef();
+                    il_sim->killMe();
                     return types::Function::Error;
                 }
             }
@@ -2070,8 +2070,6 @@ types::Function::ReturnValue sci_scicosim(types::typed_list &in, int _iRetCount,
                 il_state->killMe();
                 il_tcur->DecreaseRef();
                 il_tcur->killMe();
-                il_sim->DecreaseRef();
-                il_sim->killMe();
                 delete[] il_sim_labptr;
                 delete_strings(l_sim_lab, il_sim_lab->getSize());
                 delete[] il_sim_uidptr;
@@ -2087,6 +2085,8 @@ types::Function::ReturnValue sci_scicosim(types::typed_list &in, int _iRetCount,
                 delete[] ozsz;
                 delete[] oztyp;
                 FREE(outtb_elem);
+                il_sim->DecreaseRef();
+                il_sim->killMe();
                 return types::Function::Error;
             }
             for (int i = 0; i < outtbsz[j]*outtbsz[j + nlnk]; ++i)
@@ -2294,8 +2294,6 @@ types::Function::ReturnValue sci_scicosim(types::typed_list &in, int _iRetCount,
         il_state->killMe();
         il_tcur->DecreaseRef();
         il_tcur->killMe();
-        il_sim->DecreaseRef();
-        il_sim->killMe();
         delete[] il_sim_labptr;
         delete_strings(l_sim_lab, il_sim_lab->getSize());
         delete[] il_sim_uidptr;
@@ -2304,6 +2302,8 @@ types::Function::ReturnValue sci_scicosim(types::typed_list &in, int _iRetCount,
         {
             delete[] error;
         }
+        il_sim->DecreaseRef();
+        il_sim->killMe();
         return types::Function::Error;
     }
 
@@ -2322,10 +2322,8 @@ types::Function::ReturnValue sci_scicosim(types::typed_list &in, int _iRetCount,
     delete_strings(l_sim_lab, il_sim_lab->getSize());
     delete[] il_sim_uidptr;
     delete_strings(l_sim_uid, il_sim_uid->getSize());
-
     il_sim->DecreaseRef();
     il_sim->killMe();
-
     return types::Function::OK;
 }
 
index 01aae76..079b16d 100644 (file)
@@ -45,6 +45,6 @@ Info = scicos_simulate(scs_m,list());
 !                                                                     !
 !messagebox:                                                          !
 !                                                                     !
-!messagebox: Generated files path: TMPDIR/          !
+!messagebox: Generated files path: TMPDIR/         !
 !                                                                     !
 !messagebox:                                                          !