ast, elementary_functions, string, fileio, output_stream memory leaks 00/17100/2
Antoine ELIAS [Mon, 17 Aug 2015 13:58:47 +0000 (15:58 +0200)]
Change-Id: I03c514074aad77ad5971adb75352bed98b378932

40 files changed:
scilab/.gitignore
scilab/modules/ast/includes/ast/treevisitor.hxx
scilab/modules/ast/includes/types/list.hxx
scilab/modules/ast/src/cpp/ast/treevisitor.cpp
scilab/modules/ast/src/cpp/types/list.cpp
scilab/modules/core/sci_gateway/cpp/sci_macr2tree.cpp
scilab/modules/elementary_functions/sci_gateway/cpp/sci_max.cpp
scilab/modules/fileio/sci_gateway/c/sci_copyfile.c
scilab/modules/fileio/sci_gateway/c/sci_fscanfMat.c
scilab/modules/fileio/sci_gateway/cpp/sci_basename.cpp
scilab/modules/fileio/sci_gateway/cpp/sci_fileinfo.cpp
scilab/modules/fileio/sci_gateway/cpp/sci_fileparts.cpp
scilab/modules/fileio/sci_gateway/cpp/sci_get_absolute_file_path.cpp
scilab/modules/fileio/sci_gateway/cpp/sci_getdrives.cpp
scilab/modules/fileio/sci_gateway/cpp/sci_getlongpathname.cpp
scilab/modules/fileio/sci_gateway/cpp/sci_getshortpathname.cpp
scilab/modules/fileio/sci_gateway/cpp/sci_mfscanf.cpp
scilab/modules/fileio/sci_gateway/cpp/sci_mget.cpp
scilab/modules/fileio/sci_gateway/cpp/sci_mgetl.cpp
scilab/modules/fileio/sci_gateway/cpp/sci_mgetstr.cpp
scilab/modules/fileio/sci_gateway/cpp/sci_msscanf.cpp
scilab/modules/fileio/sci_gateway/cpp/sci_newest.cpp
scilab/modules/fileio/src/c/createtempfilename.c
scilab/modules/fileio/src/c/dlManager.c
scilab/modules/fileio/src/c/fscanfMat.c
scilab/modules/fileio/src/c/removedir.c
scilab/modules/fileio/src/c/scanf_functions.c
scilab/modules/fileio/src/cpp/mgetl.cpp
scilab/modules/fileio/src/cpp/mgetstr.cpp
scilab/modules/functions/sci_gateway/cpp/sci_execstr.cpp
scilab/modules/hdf5/sci_gateway/cpp/sci_hdf5_listvar_v3.cpp
scilab/modules/hdf5/sci_gateway/cpp/sci_hdf5_load.cpp
scilab/modules/hdf5/sci_gateway/cpp/sci_hdf5_load_v3.cpp
scilab/modules/hdf5/src/c/h5_writeDataToFile.c
scilab/modules/output_stream/sci_gateway/cpp/sci_diary.cpp
scilab/modules/output_stream/src/cpp/DiaryList.cpp
scilab/modules/output_stream/src/cpp/DiaryList.hxx
scilab/modules/output_stream/src/cpp/diary_manager.cpp
scilab/modules/output_stream/src/cpp/scilab_sprintf.cpp
scilab/modules/string/sci_gateway/cpp/sci_regexp.cpp

index 45c8f26..426f573 100644 (file)
@@ -51,6 +51,8 @@ lib
 #
 # windows files
 #
+vld.ini
+modules/windows_tools/src/c/WScilex/memory_leak_report.txt
 
 #
 # Innosetup files (Windows)
index b27a1a3..853f69b 100644 (file)
@@ -24,7 +24,11 @@ class EXTERN_AST TreeVisitor : public DummyVisitor
 {
 public:
     TreeVisitor() : l(nullptr), eol(nullptr) {}
-    ~TreeVisitor() {}
+    ~TreeVisitor() 
+    {
+        eol->killMe();
+        l->killMe();
+    }
 
     virtual void visit(const SeqExp  &e);
     virtual void visit(const CommentExp &e);
index 4dc626b..588ad9b 100644 (file)
@@ -22,7 +22,7 @@ class EXTERN_AST List : public Container
 {
 public :
     List();
-    ~List();
+    virtual ~List();
 
 protected :
     std::vector<InternalType *>*    getData();
index edfe80e..a54e751 100644 (file)
@@ -50,7 +50,9 @@ void TreeVisitor::visit(const SeqExp  &e)
                 it->isSelectExp() ||
                 it->isIfExp())
         {
-            lst->append(getList());
+            types::InternalType* tmp = getList();
+            lst->append(tmp);
+            tmp->killMe();
         }
         else
         {
@@ -63,15 +65,24 @@ void TreeVisitor::visit(const SeqExp  &e)
             s->set(3, L"endsymbol");
             //header
             tl->append(s);
+            s->killMe();
             //expression
-            tl->append(getList());
+            types::InternalType* tmp = getList();
+            tl->append(tmp);
+            tmp->killMe();
             //lhs
             types::List* lhs = new types::List();
-            lhs->append(createVar(L"ans"));
+            tmp = createVar(L"ans");
+            lhs->append(tmp);
+            tmp->killMe();
             tl->append(lhs);
+            lhs->killMe();
             //endsymbol
-            tl->append(getVerbose(*it));
+            tmp = getVerbose(*it);
+            tl->append(tmp);
+            tmp->killMe();
             lst->append(tl);
+            tl->killMe();
         }
     }
 
@@ -153,7 +164,10 @@ void TreeVisitor::visit(const MatrixExp &e)
         if (idx >= 2)
         {
             sub->append(ope);
-            sub->append(new types::String(L"cc"));
+            ope->killMe();
+            types::InternalType* tmp = new types::String(L"cc");
+            sub->append(tmp);
+            tmp->killMe();
 
             //create a new operation
             //put previous stage in lhs and
@@ -161,28 +175,30 @@ void TreeVisitor::visit(const MatrixExp &e)
             types::List* subcolcatOperation = createOperation();
             types::List* subcolcatOperands = new types::List();
             subcolcatOperands->append(sub);
+            sub->killMe();
             //add EOL
             //subcolcatOperands->append(getEOL());
-
-            subcolcatOperands->append(getList());
+            tmp = getList();
+            subcolcatOperands->append(tmp);
+            tmp->killMe();
 
             ope = subcolcatOperands;
             sub = subcolcatOperation;
         }
         else
         {
-            ope->append(getList());
-            if (idx == 0)
-            {
-                //add EOL
-                //ope->append(getEOL());
-            }
+            types::InternalType* tmp = getList();
+            ope->append(tmp);
+            tmp->killMe();
         }
 
         ++idx;
     }
     sub->append(ope);
-    sub->append(new types::String(L"cc"));
+    ope->killMe();
+    types::InternalType* tmp = new types::String(L"cc");
+    sub->append(tmp);
+    tmp->killMe();
     l = sub;
 }
 
@@ -207,29 +223,40 @@ void TreeVisitor::visit(const MatrixLineExp &e)
         if (idx >= 2)
         {
             sub->append(ope);
-            sub->append(new types::String(L"rc"));
+            ope->killMe();
+            types::InternalType* tmp = new types::String(L"rc");
+            sub->append(tmp);
+            tmp->killMe();
             //create a new operation
             //put previous stage in lhs and
             //result in rhs
             types::List* lst = createOperation();
-            types::List* tmp = new types::List();
-            tmp->append(sub);
-            tmp->append(getList());
+            types::List* l2 = new types::List();
+            l2->append(sub);
+            sub->killMe();
+            tmp = getList();
+            l2->append(tmp);
+            tmp->killMe();
 
             //lst->append(tmp);
-            ope = tmp;
+            ope = l2;
             sub = lst;
         }
         else
         {
-            ope->append(getList());
+            types::InternalType* tmp = getList();
+            ope->append(tmp);
+            tmp->killMe();
         }
 
         ++idx;
     }
 
     sub->append(ope);
-    sub->append(new types::String(L"rc"));
+    ope->killMe();
+    types::InternalType* tmp = new types::String(L"rc");
+    sub->append(tmp);
+    tmp->killMe();
     l = sub;
 }
 
@@ -241,91 +268,98 @@ void TreeVisitor::visit(const OpExp &e)
     if (e.getOper() != OpExp::unaryMinus)
     {
         e.getLeft().accept(*this);
-        sub->append(getList());
+        types::InternalType* tmp = getList();
+        sub->append(tmp);
+        tmp->killMe();
     }
     e.getRight().accept(*this);
-    sub->append(getList());
+    types::InternalType* tmp = getList();
+    sub->append(tmp);
+    tmp->killMe();
     ope->append(sub);
+    sub->killMe();
 
     switch (e.getOper())
     {
             // Arithmetics.
         case OpExp::plus:
-            ope->append(new types::String(SCI_PLUS));
+            tmp = new types::String(SCI_PLUS);
             break;
         case OpExp::unaryMinus:
         case OpExp::minus:
-            ope->append(new types::String(SCI_MINUS));
+            tmp = new types::String(SCI_MINUS);
             break;
         case OpExp::times:
-            ope->append(new types::String(SCI_TIMES));
+            tmp = new types::String(SCI_TIMES);
             break;
         case OpExp::rdivide:
-            ope->append(new types::String(SCI_RDIVIDE));
+            tmp = new types::String(SCI_RDIVIDE);
             break;
         case OpExp::ldivide:
-            ope->append(new types::String(SCI_LDIVIDE));
+            tmp = new types::String(SCI_LDIVIDE);
             break;
         case OpExp::power:
-            ope->append(new types::String(SCI_POWER));
+            tmp = new types::String(SCI_POWER);
             break;
             // Element wise.
         case OpExp::dottimes:
-            ope->append(new types::String(SCI_DOTTIMES));
+            tmp = new types::String(SCI_DOTTIMES);
             break;
         case OpExp::dotrdivide:
-            ope->append(new types::String(SCI_DOTRDIVIDE));
+            tmp = new types::String(SCI_DOTRDIVIDE);
             break;
         case OpExp::dotldivide:
-            ope->append(new types::String(SCI_DOTLDIVIDE));
+            tmp = new types::String(SCI_DOTLDIVIDE);
             break;
         case OpExp::dotpower:
-            ope->append(new types::String(SCI_DOTPOWER));
+            tmp = new types::String(SCI_DOTPOWER);
             break;
             // Kroneckers
         case OpExp::krontimes:
-            ope->append(new types::String(SCI_KRONTIMES));
+            tmp = new types::String(SCI_KRONTIMES);
             break;
         case OpExp::kronrdivide:
-            ope->append(new types::String(SCI_KRONRDIVIDE));
+            tmp = new types::String(SCI_KRONRDIVIDE);
             break;
         case OpExp::kronldivide:
-            ope->append(new types::String(SCI_KRONLDIVIDE));
+            tmp = new types::String(SCI_KRONLDIVIDE);
             break;
             // Control
         case OpExp::controltimes:
-            ope->append(new types::String(SCI_CONTROLTIMES));
+            tmp = new types::String(SCI_CONTROLTIMES);
             break;
         case OpExp::controlrdivide:
-            ope->append(new types::String(SCI_CONTROLRDIVIDE));
+            tmp = new types::String(SCI_CONTROLRDIVIDE);
             break;
         case OpExp::controlldivide:
-            ope->append(new types::String(SCI_CONTROLLDIVIDE));
+            tmp = new types::String(SCI_CONTROLLDIVIDE);
             break;
             // Comparisons
         case OpExp::eq:
-            ope->append(new types::String(SCI_EQ));
+            tmp = new types::String(SCI_EQ);
             break;
         case OpExp::ne:
-            ope->append(new types::String(SCI_NE));
+            tmp = new types::String(SCI_NE);
             break;
         case OpExp::lt:
-            ope->append(new types::String(SCI_LT));
+            tmp = new types::String(SCI_LT);
             break;
         case OpExp::le:
-            ope->append(new types::String(SCI_LE));
+            tmp = new types::String(SCI_LE);
             break;
         case OpExp::gt:
-            ope->append(new types::String(SCI_GT));
+            tmp = new types::String(SCI_GT);
             break;
         case OpExp::ge:
-            ope->append(new types::String(SCI_GE));
+            tmp = new types::String(SCI_GE);
             break;
         default:
-            ope->append(new types::String(L"BAD OPERATOR"));
+            tmp = new types::String(L"BAD OPERATOR");
             break;
     }
 
+    ope->append(tmp);
+    tmp->killMe();
     l = ope;
 }
 
@@ -343,26 +377,28 @@ void TreeVisitor::visit(const LogicalOpExp &e)
     sub->append(getList());
     ope->append(sub);
 
-    types::String* s = new types::String(1, 1);
+    types::InternalType* tmp = nullptr;
     switch (e.getOper())
     {
         case LogicalOpExp::logicalAnd:
-            ope->append(new types::String(SCI_AND));
+            tmp = new types::String(SCI_AND);
             break;
         case LogicalOpExp::logicalOr:
-            ope->append(new types::String(SCI_OR));
+            tmp = new types::String(SCI_OR);
             break;
         case LogicalOpExp::logicalShortCutAnd:
-            ope->append(new types::String(SCI_ANDAND));
+            tmp = new types::String(SCI_ANDAND);
             break;
         case LogicalOpExp::logicalShortCutOr:
-            ope->append(new types::String(SCI_OROR));
+            tmp = new types::String(SCI_OROR);
             break;
         default:
-            ope->append(new types::String(L"BAD LOGICAL OPERATOR"));
+            tmp = new types::String(L"BAD LOGICAL OPERATOR");
             break;
     }
 
+    ope->append(tmp);
+    tmp->killMe();
     l = ope;
 }
 
@@ -381,24 +417,34 @@ void TreeVisitor::visit(const IfExp  &e)
 
     //expression -> condition
     e.getTest().accept(*this);
-    tl->append(getList());
+    types::InternalType* tmp = getList();
+    tl->append(tmp);
+    tmp->killMe();
 
     //then
     e.getThen().accept(*this);
-    tl->append(getList());
+    tmp = getList();
+    tl->append(tmp);
+    tmp->killMe();
 
     //elseif
-    tl->append(new types::List());
+    tmp = new types::List();
+    tl->append(tmp);
+    tmp->killMe();
 
     //else
     if (hasElse)
     {
         e.getElse().accept(*this);
-        tl->append(getList());
+        tmp = getList();
+        tl->append(tmp);
+        tmp->killMe();
     }
     else
     {
-        tl->append(new types::List());
+        tmp = new types::List();
+        tl->append(tmp);
+        tmp->killMe();
     }
     l = tl;
 }
@@ -409,19 +455,28 @@ void TreeVisitor::visit(const ListExp  &e)
     types::List* sub = new types::List();
 
     e.getStart().accept(*this);
-    sub->append(getList());
+    types::InternalType* tmp = getList();
+    sub->append(tmp);
+    tmp->killMe();
 
     if (e.hasExplicitStep())
     {
         e.getStep().accept(*this);
-        sub->append(getList());
+        tmp = getList();
+        sub->append(tmp);
+        tmp->killMe();
     }
 
     e.getEnd().accept(*this);
-    sub->append(getList());
+    tmp = getList();
+    sub->append(tmp);
+    tmp->killMe();
 
     ope->append(sub);
-    ope->append(new types::String(L":"));
+    sub->killMe();
+    tmp = new types::String(L":");
+    ope->append(tmp);
+    tmp->killMe();
     l = ope;
 }
 
@@ -431,7 +486,9 @@ void TreeVisitor::visit(const AssignExp &e)
 
     //expression : what to assign
     e.getRightExp().accept(*this);
-    assign->append(getList());
+    types::InternalType* tmp = getList();
+    assign->append(tmp);
+    tmp->killMe();
 
     double* dlhs = NULL;
     if (e.getRightExp().isCallExp())
@@ -447,8 +504,11 @@ void TreeVisitor::visit(const AssignExp &e)
     {
         left.accept(*this);
         types::List* lhs = new types::List();
-        lhs->append(getList());
+        tmp = getList();
+        lhs->append(tmp);
+        tmp->killMe();
         assign->append(lhs);
+        lhs->killMe();
         if (dlhs)
         {
             dlhs[0] = 1;//lhs = 1
@@ -467,14 +527,18 @@ void TreeVisitor::visit(const AssignExp &e)
         types::List* lhs = new types::List();
         //varname
         call->getName().accept(*this);
-        lhs->append(getList());
+        tmp = getList();
+        lhs->append(tmp);
+        tmp->killMe();
 
         //indexes
         ast::exps_t args = call->getArgs();
         for (auto arg : args)
         {
             arg->accept(*this);
-            lhs->append(getList());
+            tmp = getList();
+            lhs->append(tmp);
+            tmp->killMe();
         }
 
         if (dlhs)
@@ -482,12 +546,15 @@ void TreeVisitor::visit(const AssignExp &e)
             dlhs[0] = 1;//lhs = 1
         }
         ins->append(lhs);
+        lhs->killMe();
 
         //operator
         ins->append(new types::String(L"ins"));
-        types::List* tmp = new types::List();
-        tmp->append(ins);
-        assign->append(tmp);
+        types::List* lst = new types::List();
+        lst->append(ins);
+        ins->killMe();
+        assign->append(lst);
+        lst->killMe();
     }
 
     if (left.isAssignListExp())
@@ -497,7 +564,9 @@ void TreeVisitor::visit(const AssignExp &e)
         for (auto exp : lst->getExps())
         {
             exp->accept(*this);
-            lhs->append(getList());
+            tmp = getList();
+            lhs->append(tmp);
+            tmp->killMe();
         }
         if (dlhs)
         {
@@ -506,6 +575,7 @@ void TreeVisitor::visit(const AssignExp &e)
 
 
         assign->append(lhs);
+        lhs->killMe();
     }
 
     if (left.isFieldExp())
@@ -515,7 +585,9 @@ void TreeVisitor::visit(const AssignExp &e)
         types::List* lhs = new types::List();
 
         field->getHead()->accept(*this);
-        lhs->append(getList());
+        tmp = getList();
+        lhs->append(tmp);
+        tmp->killMe();
 
         if (field->getTail()->isSimpleVar())
         {
@@ -526,11 +598,13 @@ void TreeVisitor::visit(const AssignExp &e)
         {
             //never occur ?
             field->accept(*this);
-            lhs->append(getList());
+            tmp = getList();
+            lhs->append(tmp);
+            tmp->killMe();
         }
 
         ins->append(lhs);
-
+        lhs->killMe();
         //operator
         ins->append(new types::String(L"ins"));
         types::List* tmp = new types::List();
@@ -697,7 +771,9 @@ void TreeVisitor::visit(const ReturnExp &e)
         types::List* ope = new types::List();
 
         //function or varname
-        ope->append(new types::String(L"return"));
+        types::InternalType* tmp = new types::String(L"return");
+        ope->append(tmp);
+        tmp->killMe();
 
         //arguments
         for (auto arg : e.getExp().getAs<ArrayListExp>()->getExps())
@@ -786,7 +862,9 @@ void TreeVisitor::visit(const ArrayListExp  &e)
     types::List* ope = new types::List();
 
     //function or varname
-    ope->append(new types::String(L""));
+    types::InternalType* tmp = new types::String(L"");
+    ope->append(tmp);
+    tmp->killMe();
 
     //arguments
     for (auto arg : e.getExps())
@@ -912,7 +990,9 @@ types::InternalType* TreeVisitor::getEOL()
     }
 
     eol = new types::List();
-    eol->append(new types::String(L"EOL"));
+    types::InternalType* tmp = new types::String(L"EOL");
+    eol->append(tmp);
+    tmp->killMe();
     return eol;
 }
 
@@ -923,7 +1003,10 @@ types::List* TreeVisitor::createVar(const std::wstring& str)
     varstr->set(0, L"variable");
     varstr->set(1, L"name");
     var->append(varstr);
-    var->append(new types::String(str.c_str()));
+    varstr->killMe();
+    types::InternalType* tmp = new types::String(str.c_str());
+    var->append(tmp);
+    tmp->killMe();
     return var;
 }
 
index 525da63..7fb388c 100644 (file)
@@ -65,13 +65,14 @@ List::~List()
 List::List(List *_oListCopyMe)
 {
     m_plData = new std::vector<InternalType *>;
-
-    for (int i = 0 ; i < (int)_oListCopyMe->getData()->size() ; i++)
+    std::vector<InternalType *>* lData = _oListCopyMe->getData();
+    int size = lData->size();
+    for (int i = 0 ; i < size ; i++)
     {
-        append((*_oListCopyMe->getData())[i]);
+        append((*lData)[i]);
     }
 
-    m_iSize = static_cast<int>(m_plData->size());
+    m_iSize = static_cast<int>(size);
 #ifndef NDEBUG
     Inspector::addItem(this);
 #endif
index 9232920..056aed1 100644 (file)
@@ -81,19 +81,26 @@ types::Function::ReturnValue sci_macr2tree(types::typed_list &in, int _iRetCount
     types::List* o = new types::List();
     for (auto p : *outputs)
     {
-        o->append(ast::TreeVisitor::createVar(p->getSymbol().getName()));
+        types::List* var = ast::TreeVisitor::createVar(p->getSymbol().getName());
+        o->append(var);
+        delete var;
     }
 
     l->append(o);
+    o->killMe();
 
     //inputs
     types::List* i = new types::List();
     for (auto p : *inputs)
     {
-        i->append(ast::TreeVisitor::createVar(p->getSymbol().getName()));
+        types::List* var = ast::TreeVisitor::createVar(p->getSymbol().getName());
+        i->append(var);
+        var->killMe();
     }
 
     l->append(i);
+    i->killMe();
+
     //statement
     ast::TreeVisitor v;
     body->accept(v);
@@ -108,11 +115,22 @@ types::Function::ReturnValue sci_macr2tree(types::typed_list &in, int _iRetCount
     sf->set(3, L"lhsnb");
 
     funcall->append(sf);
-    funcall->append(types::Double::Empty());
-    funcall->append(new types::String(L"return"));
-    funcall->append(new types::Double(0));
+    sf->killMe();
+
+    types::InternalType* tmp = types::Double::Empty();
+    funcall->append(tmp);
+    tmp->killMe();
+
+    tmp = new types::String(L"return");
+    funcall->append(tmp);
+    tmp->killMe();
+
+    tmp = new types::Double(0);
+    funcall->append(tmp);
+    tmp->killMe();
 
     statement->append(funcall);
+    funcall->killMe();
 
     statement->append(v.getEOL());
 
index a2c0e1f..b0933ed 100644 (file)
@@ -189,6 +189,7 @@ types::Function::ReturnValue sci_MinMax(types::typed_list &in, int _iRetCount, t
         return types::Function::Error;
     }
 
+    std::vector<bool> cloned(iCountElem, true);
     for (int i = 0; i < iCountElem; i++)
     {
         types::Double* pDbl = NULL;
@@ -204,6 +205,7 @@ types::Function::ReturnValue sci_MinMax(types::typed_list &in, int _iRetCount, t
                 }
 
                 iLargerInput = 1000;
+                cloned[i] = false;
                 break;
             }
             case InternalType::ScilabInt8:
@@ -394,6 +396,13 @@ types::Function::ReturnValue sci_MinMax(types::typed_list &in, int _iRetCount, t
             out.push_back(pDblOut);
     }
 
+    for (int i = 0; i < iCountElem; ++i)
+    {
+        if (cloned[i])
+        {
+            vectDouble[i]->killMe();
+        }
+    }
     if (iLargerInput != 1000)
     {
         //do not delete for double output
index bda9807..035e795 100644 (file)
@@ -201,6 +201,8 @@ int sci_copyfile(char *fname, void* pvApiCtx)
     }
     else
     {
+        FREE(pStVarOneExpanded);
+        FREE(pStVarTwoExpanded);
         Scierror(999, _("%s: Wrong value for input argument #%d: A valid filename or directory expected.\n"), fname, 1);
         return 1;
     }
index dd1d68d..bde26d1 100644 (file)
@@ -156,6 +156,8 @@ int sci_fscanfMat(char *fname, void* pvApiCtx)
             {
                 break;
             }
+
+            freeFscanfMatResult(results);
         }
     }
     else
@@ -233,33 +235,37 @@ int sci_fscanfMat(char *fname, void* pvApiCtx)
             PutLhsVar();
             return 0;
         }
-        break;
         case FSCANFMAT_MOPEN_ERROR:
         {
             Scierror(999, _("%s: can not open file %s.\n"), fname, filename);
+            FREE(filename);
+            return 0;
         }
-        break;
         case FSCANFMAT_READLINES_ERROR:
         {
             Scierror(999, _("%s: can not read file %s.\n"), fname, filename);
+            FREE(filename);
+            return 0;
         }
-        break;
         case FSCANFMAT_FORMAT_ERROR:
         {
             Scierror(999, _("%s: Invalid format.\n"), fname);
+            FREE(filename);
+            return 0;
         }
-        break;
         case FSCANFMAT_MEMORY_ALLOCATION:
         {
             Scierror(999, _("%s: Memory allocation error.\n"), fname);
+            FREE(filename);
+            return 0;
         }
-        break;
         default:
         case FSCANFMAT_ERROR:
         {
             Scierror(999, _("%s: error.\n"), fname);
+            FREE(filename);
+            return 0;
         }
-        break;
     }
 
     FREE(filename);
index 4a83815..5b77313 100644 (file)
@@ -92,7 +92,9 @@ Function::ReturnValue sci_basename(typed_list &in, int _iRetCount, typed_list &o
     String* pOut    = new String(pS->getRows(), pS->getCols());
     for (int i = 0 ; i < pS->getSize() ; i++)
     {
-        pOut->set(i, basenameW(pS->get(i), (BOOL) iExpand));
+        wchar_t* base = basenameW(pS->get(i), (BOOL)iExpand);
+        pOut->set(i, base);
+        FREE(base);
     }
 
 
index fc6f831..88a25fb 100644 (file)
@@ -82,6 +82,13 @@ Function::ReturnValue sci_fileinfo(typed_list &in, int _iRetCount, typed_list &o
         out.push_back(pErr);
     }
 
+
+    if (pS != in[0])
+    {
+        //in case of transpose
+        pS->killMe();
+    }
+
     delete[] piErr;
     FREE(pData);
     return Function::OK;
index 64ef331..36fb727 100644 (file)
@@ -72,7 +72,6 @@ Function::ReturnValue sci_fileparts(typed_list &in, int _iRetCount, typed_list &
     }
 
     pStrPath = in[0]->getAs<types::String>();
-    pStrOut = new types::String(pStrPath->getDims(), pStrPath->getDimsArray());
 
     if (in.size() == 2)
     {
@@ -107,6 +106,7 @@ Function::ReturnValue sci_fileparts(typed_list &in, int _iRetCount, typed_list &
             return Function::Error;
         }
 
+        pStrOut = new types::String(pStrPath->getDims(), pStrPath->getDimsArray());
         for (int i = 0; i < pStrPath->getSize(); i++)
         {
             wchar_t* pPath = pStrPath->get(i);
@@ -152,6 +152,7 @@ Function::ReturnValue sci_fileparts(typed_list &in, int _iRetCount, typed_list &
     }
     else
     {
+        pStrOut = new types::String(pStrPath->getDims(), pStrPath->getDimsArray());
         pStrOut2 = new types::String(pStrPath->getDims(), pStrPath->getDimsArray());
         pStrOut3 = new types::String(pStrPath->getDims(), pStrPath->getDimsArray());
 
@@ -188,14 +189,14 @@ Function::ReturnValue sci_fileparts(typed_list &in, int _iRetCount, typed_list &
             }
             else
             {
-                delete(pStrOut3);
+                delete pStrOut3;
 
             }
         }
         else
         {
-            delete(pStrOut2);
-            delete(pStrOut3);
+            delete pStrOut2;
+            delete pStrOut3;
         }
     }
 
index 73bce51..d0d4648 100644 (file)
@@ -32,11 +32,10 @@ using namespace types;
 /*--------------------------------------------------------------------------*/
 Function::ReturnValue sci_get_absolute_file_path(types::typed_list &in, int _iRetCount, types::typed_list &out)
 {
-    int dimsArray[2]                = {1, 1};
-    wchar_t* wcsFileName            = NULL;
-    wchar_t** wcsFilesOpened        = NULL;
-    wchar_t* wcsTemp                = NULL;
-    wchar_t* wcsPath                = NULL;
+    wchar_t* wcsFileName = NULL;
+    wchar_t** wcsFilesOpened = NULL;
+    wchar_t* wcsTemp = NULL;
+    wchar_t* wcsPath = NULL;
 
     if (in.size() != 1)
     {
@@ -53,19 +52,18 @@ Function::ReturnValue sci_get_absolute_file_path(types::typed_list &in, int _iRe
     wcsFileName = in[0]->getAs<types::String>()->get(0);
     wcsFilesOpened = FileManager::getFilenames();
 
-    for (int i = FileManager::getOpenedCount() - 1; i >= 0; i--)
+    for (int i = FileManager::getOpenedCount() - 1; i >= 0; --i)
     {
         wcsTemp = wcsstr(wcsFilesOpened[i], wcsFileName);
         if (wcsTemp)
         {
             int iSize = (int)(wcsTemp - wcsFilesOpened[i]);
-            wcsPath = (wchar_t*)MALLOC((iSize + 1) * sizeof(wchar_t));
-            memcpy(wcsPath, wcsFilesOpened[i], iSize * sizeof(wchar_t));
-            wcsPath[iSize] = L'\0';
             if (wcslen(wcsFilesOpened[i]) == wcslen(wcsFileName) + iSize)
             {
-                types::String* pStringOut = new types::String(2, dimsArray);
-                pStringOut->set(0, wcsPath);
+                wcsPath = (wchar_t*)MALLOC((iSize + 1) * sizeof(wchar_t));
+                memcpy(wcsPath, wcsFilesOpened[i], iSize * sizeof(wchar_t));
+                wcsPath[iSize] = L'\0';
+                types::String* pStringOut = new types::String(wcsPath);
                 FREE(wcsPath);
                 out.push_back(pStringOut);
                 freeArrayOfWideString(wcsFilesOpened, FileManager::getOpenedCount());
index 21d1987..8e3f939 100644 (file)
@@ -22,15 +22,14 @@ extern "C"
 #include "Scierror.h"
 #include "localization.h"
 #include "getdrives.h"
+#include "freeArrayOfString.h"
 }
 /*--------------------------------------------------------------------------*/
-
-
 types::Function::ReturnValue sci_getdrives(types::typed_list &in, int _iRetCount, types::typed_list &out)
 {
     wchar_t **wcsDrives = NULL;
-    int iNbDrives       = 0;
-    int dimsArray[2]    = {1, 1};
+    int iNbDrives = 0;
+    int dimsArray[2] = {1, 1};
     types::String* pOut = NULL;
 
     if (in.size() > 0)
@@ -45,6 +44,7 @@ types::Function::ReturnValue sci_getdrives(types::typed_list &in, int _iRetCount
         dimsArray[1] = iNbDrives;
         pOut = new types::String(2, dimsArray);
         pOut->set(wcsDrives);
+        freeArrayOfWideString(wcsDrives, iNbDrives);
     }
     else
     {
index 863aa2e..ad45144 100644 (file)
@@ -50,9 +50,13 @@ Function::ReturnValue sci_getlongpathname(typed_list &in, int _iRetCount, typed_
     String* pOut1 = new String(pS->getRows() , pS->getCols());
     Bool* pOut2 = new Bool(pS->getRows() , pS->getCols());
     int* pBool = pOut2->get();
-    for (int i = 0 ; i < pS->getSize(); i++)
+    int size = pS->getSize();
+    wchar_t** p = pS->get();
+    for (int i = 0 ; i < size; i++)
     {
-        pOut1->set(i, getlongpathnameW(pS->get(i), (BOOL*) &pBool[i]));
+        wchar_t* tmp = getlongpathnameW(p[i], (BOOL*)&pBool[i]);
+        pOut1->set(i, tmp);
+        FREE(tmp);
     }
 
     out.push_back(pOut1);
index b0977c2..7388e53 100644 (file)
@@ -54,9 +54,13 @@ Function::ReturnValue sci_getshortpathname(typed_list &in, int _iRetCount, typed
     String* pOut1 = new String(pS->getRows() , pS->getCols());
     Bool* pOut2 = new Bool(pS->getRows() , pS->getCols());
     int* pBool = pOut2->get();
-    for (int i = 0 ; i < pS->getSize(); i++)
+    wchar_t** p = pS->get();
+    int size = pS->getSize();
+    for (int i = 0 ; i < size; i++)
     {
-        pOut1->set(i, getshortpathnameW(pS->get(i), (BOOL*) &pBool[i]));
+        wchar_t* tmp = getshortpathnameW(p[i], (BOOL*)&pBool[i]);
+        pOut1->set(i, tmp);
+        FREE(tmp);
     }
 
     out.push_back(pOut1);
index 20ea099..379a275 100644 (file)
@@ -35,13 +35,12 @@ extern "C"
 
 types::Function::ReturnValue sci_mfscanf(types::typed_list &in, int _iRetCount, types::typed_list &out)
 {
-    int iFile                   = -1; //default file : last opened file
-    int size                    = (int)in.size();
-    int iNiter                  = 1;
-    int iErr                    = 0;
-    wchar_t* wcsFormat          = NULL;
-    int dimsArray[2]            = {1, 1};
-    std::vector<types::InternalType*>* pIT = new std::vector<types::InternalType*>();
+    int iFile = -1; //default file : last opened file
+    int size = (int)in.size();
+    int iNiter = 1;
+    int iErr = 0;
+    wchar_t* wcsFormat = NULL;
+    std::vector<types::InternalType*> IT;
 
     int args        = 0;
     int nrow        = 0;
@@ -114,7 +113,7 @@ types::Function::ReturnValue sci_mfscanf(types::typed_list &in, int _iRetCount,
     while ((iNiter == -1) || (rowcount < iNiter))
     {
         // get current position in file
-        int iCurrentPos = mtell(iFile);
+        int iCurrentPos = static_cast<int>(mtell(iFile));
 
         // get data
         int err = do_xxscanf(L"mfscanf", fDesc, wcsFormat, &args, NULL, &retval, buf, type);
@@ -139,6 +138,7 @@ types::Function::ReturnValue sci_mfscanf(types::typed_list &in, int _iRetCount,
                 mseek(iFile, iCurrentPos, SEEK_SET);
             }
 
+            FREE(buf->c);
             break;
         }
 
@@ -147,12 +147,13 @@ types::Function::ReturnValue sci_mfscanf(types::typed_list &in, int _iRetCount,
         // EOF reached
         if (retval == -1)
         {
+            FREE(buf->c);
             break;
         }
     }
 
     unsigned int uiFormatUsed = 0;
-    for (int i = 0 ; i < ncol ; i++)
+    for (int i = 0; i < ncol; i++)
     {
         switch (type_s[i])
         {
@@ -160,14 +161,15 @@ types::Function::ReturnValue sci_mfscanf(types::typed_list &in, int _iRetCount,
             case SF_S:
             {
                 types::String* ps = new types::String(rowcount, 1);
-                for (int j = 0 ; j < rowcount ; j++)
+                for (int j = 0; j < rowcount; j++)
                 {
                     ps->set(j, data[i + ncol * j].s);
                 }
-                pIT->push_back(ps);
+                
+                IT.push_back(ps);
                 uiFormatUsed |= (1 << 1);
+                break;
             }
-            break;
             case SF_LUI:
             case SF_SUI:
             case SF_UI:
@@ -182,23 +184,24 @@ types::Function::ReturnValue sci_mfscanf(types::typed_list &in, int _iRetCount,
                 {
                     p->set(j, data[i + ncol * j].d);
                 }
-                pIT->push_back(p);
+                
+                IT.push_back(p);
                 uiFormatUsed |= (1 << 2);
+                break;
             }
-            break;
         }
     }
 
-    int sizeOfVector = (int)pIT->size();
+    Free_Scan(rowcount, ncol, type_s, &data);
+
+    int sizeOfVector = (int)IT.size();
     if (_iRetCount > 1)
     {
-        types::Double* pDouble = new types::Double(2, dimsArray);
-        pDouble->set(0, retval_s);
-        out.push_back(pDouble);
+        out.push_back(new types::Double((double)retval_s));
 
         for (int i = 0; i < sizeOfVector; i++)
         {
-            out.push_back((*pIT)[i]);
+            out.push_back(IT[i]);
         }
         for (int i = sizeOfVector + 1; i < _iRetCount; i++)
         {
@@ -217,111 +220,112 @@ types::Function::ReturnValue sci_mfscanf(types::typed_list &in, int _iRetCount,
         {
             case (1 << 1) :
             {
-                int sizeOfString = (*pIT)[0]->getAs<types::String>()->getRows();
+                int sizeOfString = IT[0]->getAs<types::String>()->getRows();
                 int dimsArrayOfRes[2] = {sizeOfString, sizeOfVector};
                 types::String* pString = new types::String(2, dimsArrayOfRes);
                 for (int i = 0; i < sizeOfVector; i++)
                 {
                     for (int j = 0; j < sizeOfString; j++)
                     {
-                        pString->set(i * sizeOfString + j, (*pIT)[i]->getAs<types::String>()->get(j));
+                        pString->set(i * sizeOfString + j, IT[i]->getAs<types::String>()->get(j));
                     }
+
+                    IT[i]->killMe();
                 }
                 out.push_back(pString);
+                break;
             }
-            break;
             case (1 << 2) :
             {
-                int sizeOfDouble = (*pIT)[0]->getAs<types::Double>()->getRows();
+                int sizeOfDouble = IT[0]->getAs<types::Double>()->getRows();
                 int dimsArrayOfRes[2] = {sizeOfDouble, sizeOfVector};
                 types::Double* pDouble = new types::Double(2, dimsArrayOfRes);
-                for (int i = 0 ; i < sizeOfVector; i++)
+                for (int i = 0; i < sizeOfVector; i++)
                 {
-                    for (int j = 0 ; j < sizeOfDouble; j++)
+                    for (int j = 0; j < sizeOfDouble; j++)
                     {
-                        pDouble->set(i * sizeOfDouble + j, (*pIT)[i]->getAs<types::Double>()->get(j));
+                        pDouble->set(i * sizeOfDouble + j, IT[i]->getAs<types::Double>()->get(j));
                     }
+
+                    IT[i]->killMe();
                 }
+
                 out.push_back(pDouble);
+                break;
             }
-            break;
-            default :
+            default:
             {
-                std::vector<types::InternalType*>* pITTemp = new std::vector<types::InternalType*>();
-                pITTemp->push_back((*pIT)[0]);
+                std::vector<types::InternalType*> ITTemp;
+                ITTemp.push_back(IT[0]);
 
                 // sizeOfVector always > 1
-                for (int i = 1 ; i < sizeOfVector ; i++) // concatenates the Cells. ex : [String 4x1] [String 4x1] = [String 4x2]
+                for (int i = 1; i < sizeOfVector; i++) // concatenates the Cells. ex : [String 4x1] [String 4x1] = [String 4x2]
                 {
-                    if (pITTemp->back()->getType() == (*pIT)[i]->getType())
+                    if (ITTemp.back()->getType() == IT[i]->getType())
                     {
-                        switch (pITTemp->back()->getType())
+                        switch (ITTemp.back()->getType())
                         {
-                            case types::InternalType::ScilabString :
+                            case types::InternalType::ScilabString:
                             {
-                                int iRows               = pITTemp->back()->getAs<types::String>()->getRows();
-                                int iCols               = pITTemp->back()->getAs<types::String>()->getCols();
-                                int arrayOfType[2]      = {iRows, iCols + 1};
-                                types::String* pType    = new types::String(2, arrayOfType);
+                                int iRows = ITTemp.back()->getAs<types::String>()->getRows();
+                                int iCols = ITTemp.back()->getAs<types::String>()->getCols();
+                                int arrayOfType[2] = {iRows, iCols + 1};
+                                types::String* pType = new types::String(2, arrayOfType);
 
-                                for (int k = 0 ; k < pITTemp->back()->getAs<types::String>()->getSize() ; k++)
+                                for (int k = 0; k < ITTemp.back()->getAs<types::String>()->getSize(); k++)
                                 {
-                                    pType->set(k, pITTemp->back()->getAs<types::String>()->get(k));
+                                    pType->set(k, ITTemp.back()->getAs<types::String>()->get(k));
                                 }
 
-                                for (int k = 0; k < (*pIT)[i]->getAs<types::String>()->getSize() ; k++)
+                                for (int k = 0; k < IT[i]->getAs<types::String>()->getSize(); k++)
                                 {
-                                    pType->set(iRows * iCols + k, (*pIT)[i]->getAs<types::String>()->get(k));
+                                    pType->set(iRows * iCols + k, IT[i]->getAs<types::String>()->get(k));
                                 }
-                                pITTemp->pop_back();
-                                pITTemp->push_back(pType);
+
+                                IT[i]->killMe();
+                                ITTemp.pop_back();
+                                ITTemp.push_back(pType);
+                                break;
                             }
-                            break;
-                            case types::InternalType::ScilabDouble :
+                            case types::InternalType::ScilabDouble:
                             {
-                                int iRows               = pITTemp->back()->getAs<types::Double>()->getRows();
-                                int iCols               = pITTemp->back()->getAs<types::Double>()->getCols();
-                                int arrayOfType[2]      = {iRows, iCols + 1};
-                                types::Double* pType    = new types::Double(2, arrayOfType);
+                                int iRows = ITTemp.back()->getAs<types::Double>()->getRows();
+                                int iCols = ITTemp.back()->getAs<types::Double>()->getCols();
+                                int arrayOfType[2] = {iRows, iCols + 1};
+                                types::Double* pType = new types::Double(2, arrayOfType);
 
-                                pType->set(pITTemp->back()->getAs<types::Double>()->get());
-                                for (int k = 0; k < (*pIT)[i]->getAs<types::Double>()->getSize() ; k++)
+                                pType->set(ITTemp.back()->getAs<types::Double>()->get());
+                                for (int k = 0; k < IT[i]->getAs<types::Double>()->getSize(); k++)
                                 {
-                                    pType->set(iRows * iCols + k, (*pIT)[i]->getAs<types::Double>()->get(k));
+                                    pType->set(iRows * iCols + k, IT[i]->getAs<types::Double>()->get(k));
                                 }
-                                pITTemp->pop_back();
-                                pITTemp->push_back(pType);
+  
+                                IT[i]->killMe();
+                                ITTemp.pop_back();
+                                ITTemp.push_back(pType);
+                                break;
                             }
-                            break;
-                            default :
+                            default:
                                 return types::Function::Error;
                         }
                     }
                     else
                     {
-                        pITTemp->push_back((*pIT)[i]);
+                        ITTemp.push_back(IT[i]);
                     }
                 }
 
                 types::MList* pMList = new types::MList();
                 pMList->append(new types::String(L"cblock"));
-                for (int i = 0 ; i < pITTemp->size() ; i++)
+                for (int i = 0; i < ITTemp.size(); i++)
                 {
-                    pMList->append((*pITTemp)[i]);
+                    pMList->append(ITTemp[i]);
                 }
                 out.push_back(pMList);
-
-                //                int dimsArrayOfCell[2] = {1, (int)pITTemp->size()};
-                //                types::Cell* pCell = new types::Cell(2, dimsArrayOfCell);
-                //                for (int i = 0 ; i < pITTemp->size() ; i++)
-                //                {
-                //                    pCell->set(i, (*pITTemp)[i]);
-                //                }
-                //                out.push_back(pCell);
             }
         }
     }
-    Free_Scan(rowcount, ncol, type_s, &data);
+
     return types::Function::OK;
 }
 /*--------------------------------------------------------------------------*/
index b102736..a5795a8 100644 (file)
@@ -36,7 +36,6 @@ Function::ReturnValue sci_mget(typed_list &in, int _iRetCount, typed_list &out)
     char* pstType   = os_strdup("l");//default type value : long
     int iSize       = 0;
     int iFile       = -1; //default file : last opened file
-    double* pData   = NULL;
     int iErr        = 0;
 
     if (in.size() < 1 || in.size() > 3)
@@ -85,9 +84,6 @@ Function::ReturnValue sci_mget(typed_list &in, int _iRetCount, typed_list &out)
         iFile = static_cast<int>(in[2]->getAs<Double>()->get(0));
     }
 
-    Double* pD = new Double(1, iSize);
-    pData = pD->getReal();
-
     switch (iFile)
     {
         case 0: // stderr
@@ -107,6 +103,8 @@ Function::ReturnValue sci_mget(typed_list &in, int _iRetCount, typed_list &out)
     }
 
 
+    Double* pD = new Double(1, iSize);
+    double* pData = pD->get();
     C2F(mget)(&iFile, pData, &iSize, pstType, &iErr);
     FREE(pstType);
     if (iErr > 0)
index 131a66a..b4a0b65 100644 (file)
@@ -26,6 +26,7 @@ extern "C"
 #include "mopen.h"
 #include "mclose.h"
 #include "expandPathVariable.h"
+#include "freeArrayOfString.h"
 }
 
 using namespace types;
@@ -147,20 +148,15 @@ Function::ReturnValue sci_mgetl(typed_list &in, int _iRetCount, typed_list &out)
         String *pS = new String(iLinesRead, 1);
         pS->set(wcReadedStrings);
         out.push_back(pS);
+        freeArrayOfWideString(wcReadedStrings, iLinesRead);
     }
     else
     {
         out.push_back(types::Double::Empty());
-    }
-
-    if (wcReadedStrings)
-    {
-        for (int i = 0; i < iLinesRead; i++)
+        if (wcReadedStrings)
         {
-            FREE(wcReadedStrings[i]);
+            FREE(wcReadedStrings);
         }
-
-        FREE(wcReadedStrings);
     }
 
     if (bCloseFile)
index 455f54d..9bb241e 100644 (file)
@@ -79,14 +79,9 @@ Function::ReturnValue sci_mgetstr(types::typed_list &in, int _iRetCount, types::
         Scierror(999, _("%s: Unable to read file %d.\n"), "mgetstr", iFile);
         return types::Function::Error;
     }
-    else
-    {
-        pOutString = new types::String(iDims, iDimsArray);
-        pOutString->set(0, pwstOut);
-    }
 
+    out.push_back(new types::String(pwstOut));
     FREE(pwstOut);
-    out.push_back(pOutString);
     return Function::OK;
 }
 /*--------------------------------------------------------------------------*/
index 1216354..c0f4855 100644 (file)
@@ -34,7 +34,7 @@ types::Function::ReturnValue sci_msscanf(types::typed_list &in, int _iRetCount,
     wchar_t* wcsFormat          = NULL;
     types::String* pStrRead     = NULL;
     int dimsArray[2]            = {1, 1};
-    std::vector<types::InternalType*>* pIT = new std::vector<types::InternalType*>();
+    std::vector<types::InternalType*> IT;
 
     int args        = 0;
     int nrow        = 0;
@@ -132,7 +132,8 @@ types::Function::ReturnValue sci_msscanf(types::typed_list &in, int _iRetCount,
                 {
                     ps->set(j, data[i + ncol * j].s);
                 }
-                pIT->push_back(ps);
+                
+                IT.push_back(ps);
                 uiFormatUsed |= (1 << 1);
             }
             break;
@@ -150,23 +151,22 @@ types::Function::ReturnValue sci_msscanf(types::typed_list &in, int _iRetCount,
                 {
                     p->set(j, data[i + ncol * j].d);
                 }
-                pIT->push_back(p);
+                
+                IT.push_back(p);
                 uiFormatUsed |= (1 << 2);
             }
             break;
         }
     }
 
-    int sizeOfVector = (int)pIT->size();
+    int sizeOfVector = (int)IT.size();
     if (_iRetCount > 1)
     {
-        types::Double* pDouble = new types::Double(2, dimsArray);
-        pDouble->set(0, retval);
-        out.push_back(pDouble);
+        out.push_back(new types::Double((double)retval));
 
         for (int i = 0; i < sizeOfVector; i++)
         {
-            out.push_back((*pIT)[i]);
+            out.push_back(IT[i]);
         }
         for (int i = sizeOfVector + 1; i < _iRetCount; i++)
         {
@@ -185,14 +185,14 @@ types::Function::ReturnValue sci_msscanf(types::typed_list &in, int _iRetCount,
         {
             case (1 << 1) :
             {
-                int sizeOfString = (*pIT)[0]->getAs<types::String>()->getRows();
+                int sizeOfString = IT[0]->getAs<types::String>()->getRows();
                 int dimsArrayOfRes[2] = {sizeOfString, sizeOfVector};
                 types::String* pString = new types::String(2, dimsArrayOfRes);
                 for (int i = 0; i < sizeOfVector; i++)
                 {
                     for (int j = 0; j < sizeOfString; j++)
                     {
-                        pString->set(i * sizeOfString + j, (*pIT)[i]->getAs<types::String>()->get(j));
+                        pString->set(i * sizeOfString + j, IT[i]->getAs<types::String>()->get(j));
                     }
                 }
                 out.push_back(pString);
@@ -200,15 +200,19 @@ types::Function::ReturnValue sci_msscanf(types::typed_list &in, int _iRetCount,
             break;
             case (1 << 2) :
             {
-                int sizeOfDouble = (*pIT)[0]->getAs<types::Double>()->getRows();
+                int sizeOfDouble = IT[0]->getAs<types::Double>()->getRows();
                 int dimsArrayOfRes[2] = {sizeOfDouble, sizeOfVector};
                 types::Double* pDouble = new types::Double(2, dimsArrayOfRes);
                 for (int i = 0; i < sizeOfVector; i++)
                 {
+                    types::Double* pdbl = IT[i]->getAs<types::Double>();
+                    double* dbl = pdbl->get();
                     for (int j = 0; j < sizeOfDouble; j++)
                     {
-                        pDouble->set(i * sizeOfDouble + j, (*pIT)[i]->getAs<types::Double>()->get(j));
+                        pDouble->set(i * sizeOfDouble + j, dbl[j]);
                     }
+
+                    pdbl->killMe();
                 }
                 out.push_back(pDouble);
             }
@@ -216,12 +220,12 @@ types::Function::ReturnValue sci_msscanf(types::typed_list &in, int _iRetCount,
             default :
             {
                 std::vector<types::InternalType*>* pITTemp = new std::vector<types::InternalType*>();
-                pITTemp->push_back((*pIT)[0]);
+                pITTemp->push_back(IT[0]);
 
                 // sizeOfVector always > 1
                 for (int i = 1; i < sizeOfVector; i++) // concatenates the Cells. ex : [String 4x1] [String 4x1] = [String 4x2]
                 {
-                    if (pITTemp->back()->getType() == (*pIT)[i]->getType())
+                    if (pITTemp->back()->getType() == IT[i]->getType())
                     {
                         switch (pITTemp->back()->getType())
                         {
@@ -236,9 +240,9 @@ types::Function::ReturnValue sci_msscanf(types::typed_list &in, int _iRetCount,
                                 {
                                     pType->set(k, pITTemp->back()->getAs<types::String>()->get(k));
                                 }
-                                for (int k = 0; k < (*pIT)[i]->getAs<types::String>()->getSize(); k++)
+                                for (int k = 0; k < IT[i]->getAs<types::String>()->getSize(); k++)
                                 {
-                                    pType->set(iRows * iCols + k, (*pIT)[i]->getAs<types::String>()->get(k));
+                                    pType->set(iRows * iCols + k, IT[i]->getAs<types::String>()->get(k));
                                 }
                                 pITTemp->pop_back();
                                 pITTemp->push_back(pType);
@@ -252,9 +256,9 @@ types::Function::ReturnValue sci_msscanf(types::typed_list &in, int _iRetCount,
                                 types::Double* pType    = new types::Double(2, arrayOfType);
 
                                 pType->set(pITTemp->back()->getAs<types::Double>()->get());
-                                for (int k = 0; k < (*pIT)[i]->getAs<types::Double>()->getSize(); k++)
+                                for (int k = 0; k < IT[i]->getAs<types::Double>()->getSize(); k++)
                                 {
-                                    pType->set(iRows * iCols + k, (*pIT)[i]->getAs<types::Double>()->get(k));
+                                    pType->set(iRows * iCols + k, IT[i]->getAs<types::Double>()->get(k));
                                 }
                                 pITTemp->pop_back();
                                 pITTemp->push_back(pType);
@@ -266,7 +270,7 @@ types::Function::ReturnValue sci_msscanf(types::typed_list &in, int _iRetCount,
                     }
                     else
                     {
-                        pITTemp->push_back((*pIT)[i]);
+                        pITTemp->push_back(IT[i]);
                     }
                 }
 
index 3b169eb..92d3102 100644 (file)
@@ -85,6 +85,7 @@ types::Function::ReturnValue sci_newest(types::typed_list &in, int _iRetCount, t
         {
             if (in[iNbrString]->isString() == FALSE)
             {
+                FREE(pwcsStringInput);
                 Scierror(999, _("%s: Wrong type for input argument #%d: A string expected.\n"), "newest", iNbrString + 1);
                 return types::Function::Error;
             }
@@ -93,6 +94,7 @@ types::Function::ReturnValue sci_newest(types::typed_list &in, int _iRetCount, t
 
         if (in[1]->getAs<types::String>()->isScalar() == false)
         {
+            FREE(pwcsStringInput);
             Scierror(999, _("%s: Wrong size for input argument #%d: A string expected.\n"), "newest", 2);
             return types::Function::Error;
         }
index 249b31e..adfd62f 100644 (file)
@@ -89,6 +89,8 @@ wchar_t *createtempfilenameW(const wchar_t *wcprefix, BOOL bShortFormat)
                 wcReturnedTempFilename = shortTempFilename;
             }
         }
+
+        FREE(wcTmpDir);
     }
 #else
     char *prefix = wide_string_to_UTF8(wcprefix);
index 881d2a9..d7d924d 100644 (file)
@@ -60,7 +60,7 @@ static void init_string(inputString *s)
 /* ==================================================================== */
 static void free_string(inputString *s)
 {
-    if (s->len && s->ptr)
+    if (s->ptr)
     {
         FREE(s->ptr);
         s->ptr = NULL;
@@ -144,6 +144,7 @@ int getProxyValues(char **proxyHost, long *proxyPort, char **proxyUserPwd)
         }
 
         FREE(values[4]);
+        FREE(values[0]);
         FREE(values);
     }
     else
@@ -172,8 +173,6 @@ char *downloadFile(char *url, char *dest, char *username, char *password, char *
         return NULL;
     }
 
-    init_string(&buffer);
-
     res = curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, errorBuffer);
     if (res != CURLE_OK)
     {
@@ -249,6 +248,7 @@ char *downloadFile(char *url, char *dest, char *username, char *password, char *
 
     if (destfile == NULL)
     {
+        FREE(destdir);
         return NULL;
     }
 
@@ -277,8 +277,14 @@ char *downloadFile(char *url, char *dest, char *username, char *password, char *
             uplen = uplen + (int)strlen(password);
         }
 
-        userpass = (char *)MALLOC((uplen + 2) * sizeof(char));
+        res = curl_easy_setopt(curl, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
+        if (res != CURLE_OK)
+        {
+            Scierror(999, "Failed to set httpauth type to ANY [%s]\n", errorBuffer);
+            return NULL;
+        }
 
+        userpass = (char *)MALLOC((uplen + 2) * sizeof(char));
         strcpy(userpass, username);
         strcat(userpass, ":");
         if (password != NULL)
@@ -286,15 +292,6 @@ char *downloadFile(char *url, char *dest, char *username, char *password, char *
             strcat(userpass, password);
         }
 
-        res = curl_easy_setopt(curl, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
-        if (res != CURLE_OK)
-        {
-            FREE(filename);
-            FREE(userpass);
-            Scierror(999, "Failed to set httpauth type to ANY [%s]\n", errorBuffer);
-            return NULL;
-        }
-
         res = curl_easy_setopt(curl, CURLOPT_USERPWD, userpass);
         if (res != CURLE_OK)
         {
@@ -302,6 +299,8 @@ char *downloadFile(char *url, char *dest, char *username, char *password, char *
             Scierror(999, _("Failed to set user:pwd [%s]\n"), errorBuffer);
             return NULL;
         }
+
+        FREE(userpass);
     } /* end authentication section */
 
     {
@@ -360,6 +359,8 @@ char *downloadFile(char *url, char *dest, char *username, char *password, char *
         return NULL;
     }
 
+    init_string(&buffer);
+
     //Get data to be written to the variable
     res = curl_easy_setopt(curl, CURLOPT_WRITEDATA, &buffer);
     if (res != CURLE_OK)
@@ -392,6 +393,7 @@ char *downloadFile(char *url, char *dest, char *username, char *password, char *
     wcfopen(file, (char*)filename, "wb");
     if (file == NULL)
     {
+        free_string(&buffer);
         Scierror(999, _("Failed opening '%s' for writing.\n"), filename);
         FREE(filename);
         return NULL;
index 71e7f52..9818099 100644 (file)
@@ -128,16 +128,8 @@ fscanfMatResult *fscanfMat(char *filename, char *format, char *separator)
     }
 
     pwsLines = mgetl(fd, -1, &nblines, &errMGETL);
-
-    lines = (char**)MALLOC(sizeof(char*) * nblines);
-    for (i = 0 ; i < nblines ; i++)
-    {
-        lines[i] = wide_string_to_UTF8(pwsLines[i]);
-    }
-
-    freeArrayOfWideString(pwsLines, nblines);
-
     mclose(fd);
+
     if (errMGETL != MGETL_NO_ERROR)
     {
         resultFscanfMat = (fscanfMatResult*)(MALLOC(sizeof(fscanfMatResult)));
@@ -153,6 +145,14 @@ fscanfMatResult *fscanfMat(char *filename, char *format, char *separator)
         return resultFscanfMat;
     }
 
+    lines = (char**)MALLOC(sizeof(char*) * nblines);
+    for (i = 0; i < nblines; i++)
+    {
+        lines[i] = wide_string_to_UTF8(pwsLines[i]);
+    }
+
+    freeArrayOfWideString(pwsLines, nblines);
+
     lines = removeEmptyLinesAtTheEnd(lines, &nblines);
     lines = removeTextLinesAtTheEnd(lines, &nblines, format, separator);
 
@@ -227,7 +227,7 @@ void freeFscanfMatResult(fscanfMatResult *resultStruct)
     {
         if (resultStruct->text)
         {
-            FREE(resultStruct->text);
+            freeArrayOfString(resultStruct->text, resultStruct->sizeText);
             resultStruct->text = NULL;
         }
 
@@ -807,6 +807,8 @@ static char ** removeTextLinesAtTheEnd(char **lines, int *sizelines, char *forma
         if (itCanBeMatrixLine(lines[i], format, separator) == FALSE)
         {
             nbLinesToRemove++;
+            FREE(lines[i]);
+            lines[i] = NULL;
         }
         else
         {
@@ -816,8 +818,9 @@ static char ** removeTextLinesAtTheEnd(char **lines, int *sizelines, char *forma
 
     if (nbLinesToRemove > 0)
     {
-        linesReturned = (char**)REALLOC(lines, sizeof(char*) * (*sizelines - nbLinesToRemove));
+        //must free last lines.
         *sizelines = *sizelines - nbLinesToRemove;
+        linesReturned = lines;
     }
     else
     {
index 5f38a38..a481286 100644 (file)
@@ -197,6 +197,12 @@ static int DeleteDirectory(wchar_t *refcstrRootDirectory)
                     }
                 }
             }
+  
+            if (strFilePath)
+            {
+                FREE(strFilePath);
+                strFilePath = NULL;
+            }
         }
         while (FindNextFileW(hFile, &FileInformation) == TRUE);
 
index 4d41c19..554009e 100644 (file)
@@ -83,7 +83,7 @@ int Store_Scan(int *nrow, int *ncol, sfdir *type_s, sfdir *type, int *retval, in
             if ( (*data = (entry *) REALLOC(*data, nc * nr * sizeof(entry))) == NULL)
             {
                 err = DO_XXPRINTF_MEM_LACK;
-                goto bad2;
+                goto bad1;
             }
         }
     }
@@ -131,8 +131,9 @@ bad1:
         {
             FREE(buf[j].c);
         }
-
+    return err;
 bad2:
+
     return err;
 }
 /*--------------------------------------------------------------------------*/
index d04435e..9821f38 100644 (file)
@@ -128,6 +128,7 @@ wchar_t **mgetl(int fd, int nbLinesIn, int *nbLinesOut, int *ierr)
                     wchar_t* tmpLine = os_wcsdup(Line);
                     memset(Line, 0x00, LINE_MAX * iLineSizeMult);
                     wcscpy(Line, &tmpLine[1]);
+                    FREE(tmpLine);
                 }
 
                 nbLines++;
index 4dd13b5..3f269e0 100644 (file)
@@ -60,6 +60,7 @@ wchar_t* mgetstr(int _iFileId, int _iSizeToRead)
                 if (feof(pF->getFiledesc()))
                 {
                     pwstOut = to_wide_string(buffer);
+                    FREE(buffer);
                     return pwstOut;
                 }
                 if (pstRes == NULL)
index fdd45de..e582384 100644 (file)
@@ -217,6 +217,7 @@ Function::ReturnValue sci_execstr(types::typed_list &in, int _iRetCount, types::
     {
         if (bErrCatch == false && bMute == false)
         {
+            delete pExp;
             ConfigVariable::macroFirstLine_end();
             ConfigVariable::setPromptMode(iPromptMode);
             throw ie;
index 84c3b5e..04d1235 100644 (file)
@@ -128,9 +128,10 @@ types::Function::ReturnValue sci_hdf5_listvar_v3(types::typed_list &in, int _iRe
         for (int i = 0; i < items; i++)
         {
             info[i].name = vars[i];
+            FREE(vars[i]);
             info[i].size = 0;
 
-            int dset = getDataSetIdFromName(iFile, vars[i]);
+            int dset = getDataSetIdFromName(iFile, info[i].name.data());
             if (dset == 0)
             {
                 break;
index 6d56996..e18f41b 100644 (file)
@@ -157,6 +157,10 @@ Function::ReturnValue sci_hdf5_load(typed_list &in, int _iRetCount, typed_list&
 
         vars->killMe();
     }
+    else
+    {
+        out.push_back(out1.front());
+    }
 
     return ret;
 }
index 28a285f..0bd0da7 100644 (file)
@@ -139,9 +139,10 @@ types::Function::ReturnValue sci_hdf5_load_v3(types::typed_list &in, int _iRetCo
             for (auto &var : vars)
             {
                 std::string s(var);
+                FREE(var);
                 if (import_variable(iFile, s) == false)
                 {
-                    Scierror(999, _("%s: Unable to load \'%s\'.\n"), fname.data(), var);
+                    Scierror(999, _("%s: Unable to load \'%s\'.\n"), fname.data(), s.data());
                     return types::Function::Error;
                 }
             }
index 39dff5c..fe162b1 100644 (file)
@@ -2359,11 +2359,13 @@ int writeBooleanMatrix6(int parent, const char* name, int dims, int* pdims, int*
     iSpace = H5Screate_simple(dims, piDims, NULL);
     if (iSpace < 0)
     {
+        FREE(piDims);
         return -1;
     }
 
     //Create the dataset and write the array data to it.
     iCompress = enableCompression(9, dims, piDims);
+    FREE(piDims);
 
     dprop = H5Pcreate(H5P_DATASET_CREATE);
     H5Pset_obj_track_times(dprop, 0);
index 89eac6f..1084ee8 100644 (file)
@@ -348,6 +348,7 @@ static int sci_diary_two_rhs(char *fname, void* pvApiCtx)
     {
         if (wcscmp(wcArgumentTwo, DIARY_SECOND_ARG_LIST) == 0)
         {
+            FREE(wcArgumentTwo);
             int m1 = 0, n1 = 0;
             sciErr = getVarDimension(pvApiCtx, piAddressVarOne, &m1, &n1);
             if (sciErr.iErr)
@@ -369,6 +370,7 @@ static int sci_diary_two_rhs(char *fname, void* pvApiCtx)
         }
         else if (wcscmp(wcArgumentTwo, DIARY_SECOND_ARG_CLOSE) == 0)
         {
+            FREE(wcArgumentTwo);
             int iType = 0;
             sciErr = getVarType(pvApiCtx, piAddressVarOne, &iType);
             if (sciErr.iErr)
@@ -395,6 +397,7 @@ static int sci_diary_two_rhs(char *fname, void* pvApiCtx)
         else if ( (wcscmp(wcArgumentTwo, DIARY_SECOND_ARG_PAUSE) == 0) ||
                   (wcscmp(wcArgumentTwo, DIARY_SECOND_ARG_OFF) == 0) )
         {
+            FREE(wcArgumentTwo);
             int iType = 0;
             sciErr = getVarType(pvApiCtx, piAddressVarOne, &iType);
             if (sciErr.iErr)
@@ -421,6 +424,7 @@ static int sci_diary_two_rhs(char *fname, void* pvApiCtx)
         else if ( (wcscmp(wcArgumentTwo, DIARY_SECOND_ARG_RESUME) == 0) ||
                   (wcscmp(wcArgumentTwo, DIARY_SECOND_ARG_ON) == 0) )
         {
+            FREE(wcArgumentTwo);
             int iType = 0;
             sciErr = getVarType(pvApiCtx, piAddressVarOne, &iType);
             if (sciErr.iErr)
@@ -446,6 +450,7 @@ static int sci_diary_two_rhs(char *fname, void* pvApiCtx)
         }
         else if (wcscmp(wcArgumentTwo, DIARY_SECOND_ARG_NEW) == 0)
         {
+            FREE(wcArgumentTwo);
             int iType = 0;
             sciErr = getVarType(pvApiCtx, piAddressVarOne, &iType);
             if (sciErr.iErr)
@@ -469,6 +474,7 @@ static int sci_diary_two_rhs(char *fname, void* pvApiCtx)
         }
         else if (wcscmp(wcArgumentTwo, DIARY_SECOND_ARG_APPEND) == 0)
         {
+            FREE(wcArgumentTwo);
             int iType = 0;
             sciErr = getVarType(pvApiCtx, piAddressVarOne, &iType);
             if (sciErr.iErr)
@@ -492,6 +498,7 @@ static int sci_diary_two_rhs(char *fname, void* pvApiCtx)
         }
         else if (wcscmp(wcArgumentTwo, DIARY_SECOND_ARG_EXISTS) == 0)
         {
+            FREE(wcArgumentTwo);
             int iType = 0;
             sciErr = getVarType(pvApiCtx, piAddressVarOne, &iType);
             if (sciErr.iErr)
@@ -517,6 +524,7 @@ static int sci_diary_two_rhs(char *fname, void* pvApiCtx)
         }
         else
         {
+            FREE(wcArgumentTwo);
             Scierror(999, _("%s: Wrong value for input argument #%d.\n"), fname, 2);
             return 0;
         }
@@ -792,9 +800,11 @@ static wchar_t **getInputArgumentOneFilenames(char *fname, void* pvApiCtx, int *
                 sciErr = getMatrixOfWideString(pvApiCtx, piAddressVarOne, &m1, &n1, lenStVarOne, wcFilenames);
                 if (sciErr.iErr)
                 {
+                    FREE(lenStVarOne);
                     printError(&sciErr, 0);
                     Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, 1);
-                    return 0;
+                    *ierror = 1;
+                    return NULL;
                 }
 
                 wcFilenames = (wchar_t **)MALLOC(sizeof(wchar_t *) * (m1 * n1));
@@ -816,11 +826,13 @@ static wchar_t **getInputArgumentOneFilenames(char *fname, void* pvApiCtx, int *
                     }
 
                     sciErr = getMatrixOfWideString(pvApiCtx, piAddressVarOne, &m1, &n1, lenStVarOne, wcFilenames);
+                    FREE(lenStVarOne);
                     if (sciErr.iErr)
                     {
                         printError(&sciErr, 0);
                         Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, 1);
-                        return 0;
+                        *ierror = 1;
+                        return NULL;
                     }
 
                     *sizeReturnedArray = m1 * n1;
@@ -974,14 +986,17 @@ static wchar_t** getInputArgumentThree(char *fname, void* pvApiCtx, int *sizeRet
                 sciErr = getMatrixOfWideString(pvApiCtx, piAddressVarThree, &m3, &n3, lenStVarThree, wcInputArgumentThree);
                 if (sciErr.iErr)
                 {
+                    FREE(lenStVarThree);
                     printError(&sciErr, 0);
                     Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, 3);
-                    return 0;
+                    *ierror = 1;
+                    return NULL;
                 }
 
                 wcInputArgumentThree = (wchar_t **)MALLOC(sizeof(wchar_t *) * (m3 * n3));
                 if (wcInputArgumentThree == NULL)
                 {
+                    FREE(lenStVarThree);
                     Scierror(999, _("%s: Memory allocation error.\n"), fname);
                     *ierror = 1;
                 }
@@ -993,6 +1008,7 @@ static wchar_t** getInputArgumentThree(char *fname, void* pvApiCtx, int *sizeRet
                     }
 
                     sciErr = getMatrixOfWideString(pvApiCtx, piAddressVarThree, &m3, &n3, lenStVarThree, wcInputArgumentThree);
+                    FREE(lenStVarThree);
                     if (sciErr.iErr)
                     {
                         printError(&sciErr, 0);
index ad89e9c..e80da76 100644 (file)
@@ -99,23 +99,17 @@ std::wstring DiaryList::getFilename(int ID_diary)
     return wFilename;
 }
 /*--------------------------------------------------------------------------*/
-std::wstring * DiaryList::getFilenames(int *sizeFilenames)
+std::list<std::wstring> DiaryList::getFilenames()
 {
-    std::wstring *wFilenames = NULL;
-    *sizeFilenames = 0;
-
     LSTDIARY.sort(compareDiary);
+    int size = (int)LSTDIARY.size();
+    std::list<std::wstring> wFilenames(size);
 
-    *sizeFilenames = (int)LSTDIARY.size();
-    if (*sizeFilenames > 0)
+    if (size > 0)
     {
-        int i = 0;
-        std::list<Diary>::iterator iter;
-        wFilenames = new std::wstring[*sizeFilenames];
-
-        for ( iter = LSTDIARY.begin(); iter != LSTDIARY.end(); iter++)
+        for (auto& iter : LSTDIARY)
         {
-            wFilenames[i++] = iter->getFilename();
+            wFilenames.push_back(iter.getFilename());
         }
     }
     return wFilenames;
index 2ed81bf..cc8cfbd 100644 (file)
@@ -42,7 +42,7 @@ public:
     int * getIDs(int *sizeID);
 
     /* get filenames of diaries */
-    std::wstring * getFilenames(int *sizeFilenames);
+    std::list<std::wstring> getFilenames();
 
     /* get filename by IDs */
     std::wstring getFilename(int ID_diary);
index f872b77..4fe6830 100644 (file)
@@ -60,14 +60,17 @@ wchar_t **getDiaryFilenames(int *array_size)
     *array_size = 0;
     if (SCIDIARY)
     {
-        std::wstring * wstringFilenames = SCIDIARY->getFilenames(array_size);
+        std::list<std::wstring> wstringFilenames = SCIDIARY->getFilenames();
+        *array_size = (int)wstringFilenames.size();
         if (array_size > 0)
         {
             wchar_t **wcFilenames = (wchar_t **) MALLOC (sizeof(wchar_t*) * (*array_size));
-            for (int i = 0; i < *array_size; i++)
+            int i = 0;
+            for (const auto& filename : wstringFilenames)
             {
-                wcFilenames[i] = (wchar_t*) MALLOC(sizeof(wchar_t) * (wstringFilenames[i].length() + 1));
-                wcscpy(wcFilenames[i], wstringFilenames[i].c_str());
+                wcFilenames[i] = (wchar_t*)MALLOC(sizeof(wchar_t) * (filename.length() + 1));
+                wcscpy(wcFilenames[i], filename.data());
+                ++i;
             }
             return wcFilenames;
         }
index 20368b2..2581640 100644 (file)
@@ -241,6 +241,7 @@ wchar_t** scilab_sprintf(const std::string& funcname, const wchar_t* _pwstInput,
                 {
                     if (itPos == inPos.end())
                     {
+                        FREE(pwstFirstOutput);
                         Scierror(999, _("%s: Wrong number of input arguments: data doesn't fit with format.\n"), funcname.data());
                         *_piOutputRows = 0;
                         return nullptr;
@@ -250,6 +251,7 @@ wchar_t** scilab_sprintf(const std::string& funcname, const wchar_t* _pwstInput,
                     int c = (*itPos).second;
                     if (in[p]->getType() != InternalType::ScilabDouble)
                     {
+                        FREE(pwstFirstOutput);
                         Scierror(999, _("%s: Wrong number of input arguments: data doesn't fit with format.\n"), funcname.data());
                         *_piOutputRows = 0;
                         return nullptr;
@@ -268,6 +270,7 @@ wchar_t** scilab_sprintf(const std::string& funcname, const wchar_t* _pwstInput,
                 {
                     if (itPos == inPos.end())
                     {
+                        FREE(pwstFirstOutput);
                         Scierror(999, _("%s: Wrong number of input arguments: data doesn't fit with format.\n"), funcname.data());
                         *_piOutputRows = 0;
                         return nullptr;
@@ -277,6 +280,7 @@ wchar_t** scilab_sprintf(const std::string& funcname, const wchar_t* _pwstInput,
                     int c = (*itPos).second;
                     if (in[p]->getType() != InternalType::ScilabDouble)
                     {
+                        FREE(pwstFirstOutput);
                         Scierror(999, _("%s: Wrong number of input arguments: data doesn't fit with format.\n"), funcname.data());
                         *_piOutputRows = 0;
                         return nullptr;
@@ -296,6 +300,7 @@ wchar_t** scilab_sprintf(const std::string& funcname, const wchar_t* _pwstInput,
                 {
                     if (itPos == inPos.end())
                     {
+                        FREE(pwstFirstOutput);
                         Scierror(999, _("%s: Wrong number of input arguments: data doesn't fit with format.\n"), funcname.data());
                         *_piOutputRows = 0;
                         return nullptr;
@@ -305,6 +310,7 @@ wchar_t** scilab_sprintf(const std::string& funcname, const wchar_t* _pwstInput,
                     int c = (*itPos).second;
                     if (in[p]->getType() != InternalType::ScilabDouble)
                     {
+                        FREE(pwstFirstOutput);
                         Scierror(999, _("%s: Wrong number of input arguments: data doesn't fit with format.\n"), funcname.data());
                         *_piOutputRows = 0;
                         return nullptr;
@@ -321,6 +327,7 @@ wchar_t** scilab_sprintf(const std::string& funcname, const wchar_t* _pwstInput,
                 {
                     if (itPos == inPos.end())
                     {
+                        FREE(pwstFirstOutput);
                         Scierror(999, _("%s: Wrong number of input arguments: data doesn't fit with format.\n"), funcname.data());
                         *_piOutputRows = 0;
                         return nullptr;
@@ -330,6 +337,7 @@ wchar_t** scilab_sprintf(const std::string& funcname, const wchar_t* _pwstInput,
                     int c = (*itPos).second;
                     if (in[p]->getType() != InternalType::ScilabString)
                     {
+                        FREE(pwstFirstOutput);
                         Scierror(999, _("%s: Wrong number of input arguments: data doesn't fit with format.\n"), funcname.data());
                         *_piOutputRows = 0;
                         return nullptr;
@@ -347,6 +355,7 @@ wchar_t** scilab_sprintf(const std::string& funcname, const wchar_t* _pwstInput,
                     break;
                 }
                 default:
+                    FREE(pwstFirstOutput);
                     Scierror(999, _("%s: Wrong number of input arguments: data doesn't fit with format.\n"), funcname.data());
                     *_piOutputRows = 0;
                     return nullptr;
index c30baef..1140f78 100644 (file)
@@ -123,7 +123,7 @@ Function::ReturnValue sci_regexp(typed_list &in, int _iRetCount, typed_list &out
     piStart     = new int[wcslen(pwstInput)];
     piEnd       = new int[wcslen(pwstInput)];
 
-    pwstCapturedString = (wchar_t***)MALLOC(sizeof(wchar_t**) * wcslen(pwstInput));
+    pwstCapturedString = (wchar_t***)CALLOC(sizeof(wchar_t**), wcslen(pwstInput));
     piCapturedStringCount = (int*)CALLOC(sizeof(int), wcslen(pwstInput));
 
     do
@@ -178,6 +178,7 @@ Function::ReturnValue sci_regexp(typed_list &in, int _iRetCount, typed_list &out
             out.push_back(new String(L""));
         }
 
+        freeArrayOfWideString(pwstCapturedString[0], piCapturedStringCount[0]);
         FREE(pwstCapturedString);
         FREE(piCapturedStringCount);
         delete[] piStart;
@@ -263,15 +264,14 @@ Function::ReturnValue sci_regexp(typed_list &in, int _iRetCount, typed_list &out
                     index++;
                 }
             }
-
         }
-        out.push_back(pS);
 
-        for (int i = 0; i < iOccurs; i++)
-        {
-            freeArrayOfWideString(pwstCapturedString[i], piCapturedStringCount[i]);
-        }
+        out.push_back(pS);
+    }
 
+    for (int i = 0; i < iOccurs; i++)
+    {
+        freeArrayOfWideString(pwstCapturedString[i], piCapturedStringCount[i]);
     }
 
     FREE(pwstCapturedString);