Coverity: history_manager module memory errors fixed 67/18367/5
Dhruv Khattar [Fri, 15 Jul 2016 22:21:41 +0000 (03:21 +0530)]
Change-Id: I3e190da37c65e780cc7197c4b8035dd7d7067091

scilab/modules/history_manager/sci_gateway/cpp/sci_removelinehistory.cpp
scilab/modules/history_manager/src/c/getCommentDateSession.c
scilab/modules/history_manager/src/cpp/HistoryManager.cpp

index f6b7d6e..6ff04ed 100644 (file)
@@ -50,6 +50,7 @@ types::Function::ReturnValue sci_removelinehistory(types::typed_list &in, int _i
             do
             {
                 HistoryManager::getInstance()->deleteNthLine(pDbl->get(0));
+                FREE(pcLigne);
                 pcLigne = HistoryManager::getInstance()->getNthLine(pDbl->get(0));
                 size = HistoryManager::getInstance()->getNumberOfLines();
             }
@@ -59,6 +60,7 @@ types::Function::ReturnValue sci_removelinehistory(types::typed_list &in, int _i
         {
             HistoryManager::getInstance()->deleteNthLine(pDbl->get(0));
         }
+        FREE(pcLigne);
     }
     else
     {
index 2380baf..8226d87 100644 (file)
@@ -27,6 +27,7 @@
 /*------------------------------------------------------------------------*/
 #define STRING_BEGIN_SESSION _("Begin Session : ")
 #define FORMAT_SESSION "%s%s%s"
+#define LONG_FORMAT_SESSION "%s%s%s%s"
 #define MAX_wday 7              /* number days in a week */
 #define MAX_mon 12              /* number of month in a year */
 /*------------------------------------------------------------------------*/
@@ -66,7 +67,7 @@ char *getCommentDateSession(BOOL longFormat)
         {
             if (longFormat)
             {
-                sprintf(line, FORMAT_SESSION, SESSION_PRAGMA_BEGIN, STRING_BEGIN_SESSION, time_str, SESSION_PRAGMA_END);
+                sprintf(line, LONG_FORMAT_SESSION, SESSION_PRAGMA_BEGIN, STRING_BEGIN_SESSION, time_str, SESSION_PRAGMA_END);
             }
             else
             {
@@ -102,6 +103,7 @@ static char *ASCIItime(const struct tm *timeptr)
     }
     else
     {
+        result = (char *)MALLOC(sizeof(char));
         strcpy(result, "");
     }
 
index e6b1537..7594d22 100644 (file)
@@ -354,11 +354,8 @@ BOOL HistoryManager::appendLine(char* _pstLine)
             m_iSavedLines = 0;
         }
 
-        if (pstCleanedLine)
-        {
-            FREE(pstCleanedLine);
-            pstCleanedLine = NULL;
-        }
+        FREE(pstCleanedLine);
+        pstCleanedLine = NULL;
     }
 
     return bOK;