CovertyFix-CID:1098466 Resource Leak 52/19652/5
Nimish Kapoor [Mon, 8 Jan 2018 19:14:06 +0000 (00:14 +0530)]
Change-Id: I0fb37023586aae50c504f975df2ce3f5eb1c389b

scilab/modules/gui/sci_gateway/cpp/sci_uigetdir.cpp

index be7925a..da1184c 100644 (file)
@@ -156,6 +156,16 @@ int sci_uigetdir(char *fname, void* pvApiCtx)
         if (sciErr.iErr)
         {
             Scierror(999, _("%s: Memory allocation error.\n"), fname);
+            for (int i = 0; i < nbRow; i++)
+            {
+                if (userSelection[i])
+                {
+                    delete userSelection[i];
+                    userSelection[i] = NULL;
+                }
+            }
+            delete[]userSelection;
+            userSelection = NULL;
             return 1;
         }
 
@@ -182,6 +192,8 @@ int sci_uigetdir(char *fname, void* pvApiCtx)
         {
             printError(&sciErr, 0);
             Scierror(999, _("%s: Memory allocation error.\n"), fname);
+            delete[]userSelection;
+            userSelection = NULL;
             return 1;
         }
     }