Coverity: String module Resource Leaks fixed 37/18137/3
Dhruv Khattar [Wed, 4 May 2016 10:39:21 +0000 (15:39 +0530)]
Change-Id: I861cd0d53cbc0440cdd8d8cbafd515f61bf609fa

scilab/modules/string/sci_gateway/cpp/sci_grep.cpp
scilab/modules/string/sci_gateway/cpp/sci_tokens.cpp
scilab/modules/string/src/c/pcre_private.c
scilab/modules/string/src/c/strsubst.c

index 75027da..cff3be3 100644 (file)
@@ -331,6 +331,12 @@ static int GREP_NEW(GREPRESULTS *results, char **Inputs_param_one, int mn_one, c
             save = os_strdup(Inputs_param_two[x]);
             answer = pcre_private(Inputs_param_one[y], save, &Output_Start, &Output_End, NULL, NULL);
 
+            if (save)
+            {
+                FREE(save);
+                save = NULL;
+            }
+
             if ( answer == PCRE_FINISHED_OK )
             {
                 results->values[results->currentLength] = y + 1;
@@ -342,12 +348,6 @@ static int GREP_NEW(GREPRESULTS *results, char **Inputs_param_one, int mn_one, c
                 pcre_error("grep", answer);
                 return GREP_ERROR;
             }
-
-            if (save)
-            {
-                FREE(save);
-                save = NULL;
-            }
         }
     }
 
index 409a6e9..6f5fe0a 100644 (file)
@@ -95,6 +95,7 @@ types::Function::ReturnValue sci_tokens(types::typed_list &in, int _iRetCount, t
             {
                 Scierror(999, _("%s: Wrong type for input argument #%d: Char(s) expected.\n"), "tokens", 2);
                 delete pOutString;
+                FREE(seps);
                 return types::Function::Error;
             }
             seps[i] = pCharSample->get(i)[0];
index e5dc3c9..9aa7d99 100644 (file)
@@ -242,6 +242,7 @@ pcre_error_code pcre_private(char *INPUT_LINE, char *INPUT_PAT, int *Output_Star
         }
         if (*p == 0)
         {
+            FREE(back_p);
             continue;
         }
         /* In-line pattern (the usual case). Get the delimiter and seek the end of
@@ -400,6 +401,11 @@ pcre_error_code pcre_private(char *INPUT_LINE, char *INPUT_PAT, int *Output_Star
                             FREE(buffer);
                             buffer = NULL;
                         }
+                        if (back_p)
+                        {
+                            FREE(back_p);
+                            back_p = NULL;
+                        }
                         if (offsets)
                         {
                             FREE(offsets);
index 79ee14d..7cd9b70 100644 (file)
@@ -185,7 +185,7 @@ char *strsub_reg(const char* input_string, const char* string_to_search, const c
     wcreplacedString = (wchar_t*)MALLOC (sizeof(wchar_t) * (len + 1));
     if (wcreplacedString == NULL)
     {
-        FREE(replacement_string);
+        FREE(wcreplacement_string);
         FREE(wcinput_string);
         return NULL;
     }