memory leak
Allan CORNET [Tue, 25 Aug 2009 08:14:22 +0000 (10:14 +0200)]
scilab/modules/output_stream/sci_gateway/cpp/sci_diary.cpp
scilab/modules/output_stream/src/cpp/diary_manager.cpp

index 7651523..9d468f7 100644 (file)
@@ -139,8 +139,7 @@ static int sci_diary_no_rhs(char *fname)
                        createMatrixOfWideString(Rhs + 2, nb_diary_filenames, 1, wcdiary_filenames);
                        LhsVar(2) = Rhs + 2;
 
-                       delete [] wcdiary_filenames;
-                       wcdiary_filenames = NULL;
+                       freeInput(wcdiary_filenames, nb_diary_filenames);
                        nb_diary_filenames = 0;
                }
                else
@@ -151,8 +150,7 @@ static int sci_diary_no_rhs(char *fname)
                                LhsVar(2) = Rhs + 2;
                                if (wcdiary_filenames)
                                {
-                                       delete [] wcdiary_filenames;
-                                       wcdiary_filenames = NULL;
+                                       freeInput(wcdiary_filenames, nb_diary_filenames);
                                        nb_diary_filenames = 0;
                                }
                        }
@@ -232,7 +230,7 @@ static int sci_diary_one_rhs(char *fname)
                                        wfilenameUsed[0] = getDiaryFilename((int)dID);
                                        createMatrixOfWideString(Rhs + 2, 1, 1, wfilenameUsed);
                                        LhsVar(2) = Rhs + 2;
-                                       if (wfilenameUsed) {delete [] wfilenameUsed; wfilenameUsed = NULL;}
+                                       freeInput(wfilenameUsed,1);
                                }
                        }
                        else // diary(filename) exists (close diary)
@@ -1054,7 +1052,7 @@ static int AppendByFilenames(char *fname,
                        wfilenameUsed[0] = getDiaryFilename((int)dID);
                        createMatrixOfWideString(Rhs + 2, 1, 1, wfilenameUsed);
                        LhsVar(2) = Rhs + 2;
-                       if (wfilenameUsed) {delete [] wfilenameUsed; wfilenameUsed = NULL;}
+                       freeInput(wfilenameUsed, 1);
                }
                C2F(putlhsvar)();
        }
@@ -1115,7 +1113,7 @@ static int NewByFilenames(char *fname,
                        wfilenameUsed[0] = getDiaryFilename((int)dID);
                        createMatrixOfWideString(Rhs + 2, 1, 1, wfilenameUsed);
                        LhsVar(2) = Rhs + 2;
-                       if (wfilenameUsed) {delete [] wfilenameUsed; wfilenameUsed = NULL;}
+                       freeInput(wfilenameUsed, 1);
                }
                C2F(putlhsvar)();
        }
index 96533e1..a030440 100644 (file)
@@ -13,6 +13,7 @@
 #include "diary_manager.hxx"
 #include "DiaryList.hxx"
 #include "diary.h"
+#include "MALLOC.h"
 /*--------------------------------------------------------------------------*/
 static DiaryList *SCIDIARY = NULL;
 /*--------------------------------------------------------------------------*/
@@ -44,8 +45,8 @@ wchar_t *getDiaryFilename(int _Id)
        {
                if (SCIDIARY->getFilename(_Id).compare(L""))
                {
-                       wcFilename = new wchar_t[SCIDIARY->getFilename(_Id).length()];
-                       wcscpy(wcFilename, SCIDIARY->getFilename(_Id).c_str());
+                       wcFilename = (wchar_t*) MALLOC(sizeof(wchar_t) * (SCIDIARY->getFilename(_Id).length() + 1));
+                       if (wcFilename) wcscpy(wcFilename, SCIDIARY->getFilename(_Id).c_str());
                }
        }
        return wcFilename;
@@ -59,10 +60,10 @@ wchar_t **getDiaryFilenames(int *array_size)
                std::wstring * wstringFilenames = SCIDIARY->getFilenames(array_size);
                if (array_size > 0)
                {
-                       wchar_t **wcFilenames = new wchar_t*[*array_size]; 
+                       wchar_t **wcFilenames = (wchar_t **) MALLOC (sizeof(wchar_t*) *(*array_size)); 
                        for(int i = 0; i < *array_size; i++)
                        {
-                               wcFilenames[i] = new wchar_t[wstringFilenames[i].length()];
+                               wcFilenames[i] = (wchar_t*) MALLOC(sizeof(wchar_t) * (wstringFilenames[i].length() + 1));
                                wcscpy(wcFilenames[i], wstringFilenames[i].c_str());
                        }
                        return wcFilenames;