Coverity #1098375 Resource Leak fix 57/17957/10
Aashish Misraa [Wed, 23 Mar 2016 08:56:57 +0000 (13:56 +0530)]
Change-Id: I014f5ef387cfa2d115639d5a7f578db74b18ed0a

scilab/modules/graphics/sci_gateway/cpp/sci_xset.cpp

index 7dcd562..34af825 100644 (file)
@@ -291,7 +291,7 @@ types::Function::ReturnValue sci_xset(types::typed_list &in, int _iRetCount, typ
             // reset format
             ConfigGraphicVariable::setFPF(L"");
 
-            double* pdblColorMap = (double*)malloc(m * 3 * sizeof(double));
+            double* pdblColorMap = new double[m * 3];
             if (pdblColorMap == NULL)
             {
                 Scierror(999, _("%s: No more memory.\n"), "xset");
@@ -304,6 +304,7 @@ types::Function::ReturnValue sci_xset(types::typed_list &in, int _iRetCount, typ
             {
                 iFigureUID = createNewFigureWithAxes();
                 setCurrentFigure(iFigureUID);
+                delete[] pdblColorMap;
                 return types::Function::OK;
             }
 
@@ -361,6 +362,7 @@ types::Function::ReturnValue sci_xset(types::typed_list &in, int _iRetCount, typ
 
             setGraphicObjectProperty(iFigureUID, __GO_COLORMAP__, pdblColorMap, jni_double_vector, 3 * m);
             setGraphicObjectProperty(iFigureUID, __GO_PARENT__, "", jni_string, 1);
+            delete[] pdblColorMap;
         }
         break;
         case 6 : // clipgrf