ast: fix memleaks detected by ASAN during testing
[scilab.git] / scilab / modules / ast / src / cpp / types / types_tools.cpp
index c98fb9e..d50cf5a 100644 (file)
@@ -816,6 +816,12 @@ int checkIndexesArguments(InternalType* _pRef, typed_list* _pArgsIn, typed_list*
                 {
                     wchar_t szError[bsiz];
                     os_swprintf(szError, bsiz, _W("variable size exceeded : less than %d expected.\n").c_str(), INT_MAX);
+
+                    if(_pRef)
+                    {
+                        _pRef->killMe(); // clean temporary clone if needed
+                    }
+
                     throw ast::InternalError(szError);
                 }
 
@@ -841,10 +847,15 @@ int checkIndexesArguments(InternalType* _pRef, typed_list* _pArgsIn, typed_list*
             delete[] _piCountDim;
             cleanIndexesArguments(_pArgsIn, _pArgsOut);
 
+            if(_pRef)
+            {
+                _pRef->killMe(); // clean temporary clone if needed
+            }
+
             throw ast::InternalError(szError);
         }
-        _pArgsOut->push_back(pCurrentArg);
 
+        _pArgsOut->push_back(pCurrentArg);
     }