Bug 12232 fixed: fix several memleaks in various filler 59/10259/2
Calixte DENIZET [Sat, 19 Jan 2013 18:22:24 +0000 (19:22 +0100)]
Change-Id: I8f38a34b3c1f6f707dddf1e0fa1cb9abcd330c18

scilab/CHANGES_5.4.X
scilab/modules/graphic_objects/src/cpp/Fac3DDecomposer.cpp
scilab/modules/graphic_objects/src/cpp/MatPlotDecomposer.cpp
scilab/modules/graphic_objects/src/cpp/NgonGridGrayplotDataDecomposer.cpp
scilab/modules/graphic_objects/src/cpp/NgonGridMatplotDataDecomposer.cpp
scilab/modules/graphic_objects/src/cpp/Plot3DDecomposer.cpp
scilab/modules/graphic_objects/src/cpp/PolylineDecomposer.cpp
scilab/modules/graphic_objects/src/cpp/TriangleMeshFecDataDecomposer.cpp
scilab/modules/graphic_objects/src/cpp/getGraphicObjectProperty.cpp

index e9000c0..d0d0aa8 100644 (file)
@@ -286,6 +286,8 @@ Bug fixes
 
 * Bug #12219 fixed - delete("all") does not recreate a basic axe within cleaned figure.
 
+* Bug #12232 fixed - There were several memleaks in various fillers.
+
 
                     Changes between version 5.3.3 and 5.4.0
                     =======================================
index d69ecc4..4b8b772 100644 (file)
@@ -153,11 +153,7 @@ void Fac3DDecomposer::fillTextureCoordinates(char* id, float* buffer, int buffer
         return;
     }
 
-    getGraphicObjectProperty(parentFigure, __GO_COLORMAP__, jni_double_vector, (void**) &colormap);
-    getGraphicObjectProperty(parentFigure, __GO_COLORMAP_SIZE__, jni_int, (void**) &piColormapSize);
-
     getGraphicObjectProperty(id, __GO_COLOR_FLAG__, jni_int, (void**) &piColorFlag);
-
     getGraphicObjectProperty(id, __GO_DATA_MAPPING__, jni_int, (void**) &piDataMapping);
 
     /* Do not fill */
@@ -166,6 +162,9 @@ void Fac3DDecomposer::fillTextureCoordinates(char* id, float* buffer, int buffer
         return;
     }
 
+    getGraphicObjectProperty(parentFigure, __GO_COLORMAP__, jni_double_vector, (void**) &colormap);
+    getGraphicObjectProperty(parentFigure, __GO_COLORMAP_SIZE__, jni_int, (void**) &piColormapSize);
+
     if (numColors == numGons*numVerticesPerGon)
     {
         perVertex = 1;
@@ -205,6 +204,7 @@ void Fac3DDecomposer::fillTextureCoordinates(char* id, float* buffer, int buffer
                                          colors, colorFlag, perVertex, dataMapping, numGons, numVerticesPerGon);
     }
 
+    releaseGraphicObjectProperty(__GO_COLORMAP__, colormap, jni_double_vector, colormapSize);
 }
 
 void Fac3DDecomposer::fillNormalizedZColorsTextureCoordinates(float* buffer, int bufferLength, double* colormap, int colormapSize,
index ed02c35..0d224de 100644 (file)
@@ -66,6 +66,8 @@ int MatPlotDecomposer::fillTextureData(char* id, unsigned char* buffer, int buff
             }
         }
 
+        releaseGraphicObjectProperty(__GO_COLORMAP__, colormap, jni_double_vector, colormapSize);
+
         return bufferLength;
     }
     else
@@ -99,6 +101,9 @@ int MatPlotDecomposer::fillTextureData(char* id, unsigned char* buffer, int buff
                 k += 4;
             }
         }
+
+        releaseGraphicObjectProperty(__GO_COLORMAP__, colormap, jni_double_vector, colormapSize);
+
         return bufferLength;
     }
     else
index 53d732b..fef5f1c 100644 (file)
@@ -80,6 +80,8 @@ void NgonGridGrayplotDataDecomposer::fillColors(char* id, float* buffer, int buf
     {
         decomposer->fillDirectGridColors(buffer, bufferLength, elementsSize, colormap, colormapSize, z, numX, numY);
     }
+
+    releaseGraphicObjectProperty(__GO_COLORMAP__, colormap, jni_double_vector, colormapSize);
 }
 
 int NgonGridGrayplotDataDecomposer::fillIndices(char* id, int* buffer, int bufferLength, int logMask)
index 6ca4eaa..3804001 100644 (file)
@@ -64,11 +64,14 @@ void NgonGridMatplotDataDecomposer::fillVertices(char* id, float* buffer, int bu
      * because Matplot vertex coordinates are directly computed from these values.
      */
     decomposer->fillGridVertices(buffer, bufferLength, elementsSize, coordinateMask, scale, translation, logMask, (double*) xTrans, (double*) yTrans, &zShift, numX, numY);
+
+    releaseGraphicObjectProperty(__GO_MATPLOT_SCALE__, matplotScale, jni_double_vector, 0);
+    releaseGraphicObjectProperty(__GO_MATPLOT_TRANSLATE__, matplotTranslate, jni_double_vector, 0);
 }
 
 /* To do: refactor with its parent class' same method */
 void NgonGridMatplotDataDecomposer::fillGridVertices(float* buffer, int bufferLength, int elementsSize, int coordinateMask, double* scale, double* translation, int logMask,
-    double* x, double* y, double* z, int numX, int numY)
+                                                     double* x, double* y, double* z, int numX, int numY)
 {
     double xi = 0.;
     double yj = 0.;
@@ -243,9 +246,6 @@ void NgonGridMatplotDataDecomposer::fillColors(char* id, float* buffer, int buff
 
     getGraphicObjectProperty(id, __GO_PARENT_FIGURE__, jni_string, (void**) &parentFigure);
 
-    getGraphicObjectProperty(parentFigure, __GO_COLORMAP__, jni_double_vector, (void**) &colormap);
-    getGraphicObjectProperty(parentFigure, __GO_COLORMAP_SIZE__, jni_int, (void**) &piColormapSize);
-
     getGraphicObjectProperty(id, __GO_DATA_MODEL_NUM_X__, jni_int, (void**) &piNumX);
     getGraphicObjectProperty(id, __GO_DATA_MODEL_NUM_Y__, jni_int, (void**) &piNumY);
 
@@ -257,6 +257,9 @@ void NgonGridMatplotDataDecomposer::fillColors(char* id, float* buffer, int buff
         return;
     }
 
+    getGraphicObjectProperty(parentFigure, __GO_COLORMAP__, jni_double_vector, (void**) &colormap);
+    getGraphicObjectProperty(parentFigure, __GO_COLORMAP_SIZE__, jni_int, (void**) &piColormapSize);
+
 #if PER_VERTEX_VALUES
     for (int j = 0; j < numY-1; j++)
     {
@@ -331,6 +334,8 @@ void NgonGridMatplotDataDecomposer::fillColors(char* id, float* buffer, int buff
     }
 
 #endif
+
+    releaseGraphicObjectProperty(__GO_COLORMAP__, colormap, jni_double_vector, colormapSize);
 }
 
 /*
index 50a9577..8f46ebf 100644 (file)
@@ -71,7 +71,7 @@ double Plot3DDecomposer::getZCoordinate(double* z, int numX, int numY, int i, in
 }
 
 void Plot3DDecomposer::getFacetTriangles(double* x, double* y, double* z, int numX, int numY, int i, int j,
-    int* facetVertexIndices, int* triangleVertexIndices)
+                                         int* facetVertexIndices, int* triangleVertexIndices)
 {
     double vertices[4][3];
 
@@ -128,6 +128,8 @@ void Plot3DDecomposer::fillColors(char* id, float* buffer, int bufferLength, int
     getGraphicObjectProperty(parentFigure, __GO_COLORMAP_SIZE__, jni_int, (void**) &piColormapSize);
 
     decomposer->fillNormalizedZGridColors(buffer, bufferLength, elementsSize, colormap, colormapSize, z, numX, numY);
+
+    releaseGraphicObjectProperty(__GO_COLORMAP__, colormap, jni_double_vector, colormapSize);
 }
 
 int Plot3DDecomposer::fillIndices(char* id, int* buffer, int bufferLength, int logMask)
index 1b05e63..f9f71a6 100644 (file)
@@ -708,8 +708,6 @@ void PolylineDecomposer::fillColors(char* id, float* buffer, int bufferLength, i
     }
 
     getGraphicObjectProperty(id, __GO_DATA_MODEL_NUM_ELEMENTS__, jni_int, (void**) &piNPoints);
-    getGraphicObjectProperty(id, __GO_INTERP_COLOR_VECTOR__, jni_int_vector, (void**) &interpColorVector);
-
     getGraphicObjectProperty(id, __GO_PARENT__, jni_string, (void**) &parent);
 
     /* Temporary: to avoid getting a null parent_figure property when the object is built */
@@ -735,9 +733,6 @@ void PolylineDecomposer::fillColors(char* id, float* buffer, int bufferLength, i
         return;
     }
 
-    getGraphicObjectProperty(parentFigure, __GO_COLORMAP__, jni_double_vector, (void**) &colormap);
-    getGraphicObjectProperty(parentFigure, __GO_COLORMAP_SIZE__, jni_int, (void**) &piColormapSize);
-
     /*
      * The interpolated color vector is a 3- or 4-element vector.
      * However, if nPoints is greater than 4, we choose to output
@@ -748,6 +743,10 @@ void PolylineDecomposer::fillColors(char* id, float* buffer, int bufferLength, i
         return;
     }
 
+    getGraphicObjectProperty(id, __GO_INTERP_COLOR_VECTOR__, jni_int_vector, (void**) &interpColorVector);
+    getGraphicObjectProperty(parentFigure, __GO_COLORMAP__, jni_double_vector, (void**) &colormap);
+    getGraphicObjectProperty(parentFigure, __GO_COLORMAP_SIZE__, jni_int, (void**) &piColormapSize);
+
     if (nPoints > 4)
     {
         nPoints = 4;
@@ -764,6 +763,9 @@ void PolylineDecomposer::fillColors(char* id, float* buffer, int bufferLength, i
 
         bufferOffset += elementsSize;
     }
+
+    releaseGraphicObjectProperty(__GO_COLORMAP__, colormap, jni_double_vector, colormapSize);
+    releaseGraphicObjectProperty(__GO_INTERP_COLOR_VECTOR__, interpColorVector, jni_int_vector, 0);
 }
 
 void PolylineDecomposer::fillTextureCoordinates(char* id, float* buffer, int bufferLength)
@@ -799,8 +801,6 @@ void PolylineDecomposer::fillTextureCoordinates(char* id, float* buffer, int buf
     }
 
     getGraphicObjectProperty(id, __GO_DATA_MODEL_NUM_ELEMENTS__, jni_int, (void**) &piNPoints);
-    getGraphicObjectProperty(id, __GO_INTERP_COLOR_VECTOR__, jni_int_vector, (void**) &interpColorVector);
-
     getGraphicObjectProperty(id, __GO_PARENT__, jni_string, (void**) &parent);
 
     /* Temporary: to avoid getting a null parent_figure property when the object is built */
@@ -826,9 +826,6 @@ void PolylineDecomposer::fillTextureCoordinates(char* id, float* buffer, int buf
         return;
     }
 
-    getGraphicObjectProperty(parentFigure, __GO_COLORMAP__, jni_double_vector, (void**) &colormap);
-    getGraphicObjectProperty(parentFigure, __GO_COLORMAP_SIZE__, jni_int, (void**) &piColormapSize);
-
     /*
      * The interpolated color vector is a 3- or 4-element vector.
      * However, if nPoints is greater than 4, we choose to output
@@ -839,6 +836,10 @@ void PolylineDecomposer::fillTextureCoordinates(char* id, float* buffer, int buf
         return;
     }
 
+    getGraphicObjectProperty(id, __GO_INTERP_COLOR_VECTOR__, jni_int_vector, (void**) &interpColorVector);
+    getGraphicObjectProperty(parentFigure, __GO_COLORMAP__, jni_double_vector, (void**) &colormap);
+    getGraphicObjectProperty(parentFigure, __GO_COLORMAP_SIZE__, jni_int, (void**) &piColormapSize);
+
     if (nPoints > 4)
     {
         nPoints = 4;
@@ -855,6 +856,9 @@ void PolylineDecomposer::fillTextureCoordinates(char* id, float* buffer, int buf
 
         bufferOffset += 4;
     }
+
+    releaseGraphicObjectProperty(__GO_COLORMAP__, colormap, jni_double_vector, colormapSize);
+    releaseGraphicObjectProperty(__GO_INTERP_COLOR_VECTOR__, interpColorVector, jni_int_vector, 0);
 }
 
 /*
index c834fd7..c212006 100644 (file)
@@ -123,6 +123,8 @@ void TriangleMeshFecDataDecomposer::fillTextureCoordinates(char* id, float* buff
         colorsNumber = (double) colormapSize;
     }
 
+    releaseGraphicObjectProperty(__GO_COLOR_RANGE__, colorRange, jni_int_vector, 0);
+
     /** To take into account the presence of exterior colors:
      *  - We add 2 to the number of colors.
      *  - We skip the first color.
@@ -145,6 +147,8 @@ void TriangleMeshFecDataDecomposer::fillTextureCoordinates(char* id, float* buff
         computeMinMaxValues(values, numVertices, &minValue, &maxValue);
     }
 
+    releaseGraphicObjectProperty(__GO_Z_BOUNDS__, zBounds, jni_double_vector, 0);
+
     if (maxValue == minValue)
     {
         for (int i = 0; i < numVertices; i++)
@@ -247,6 +251,8 @@ void TriangleMeshFecDataDecomposer::fillColors(char* id, float* buffer, int buff
         maxColorIndex = colormapSize-1;
     }
 
+    releaseGraphicObjectProperty(__GO_COLOR_RANGE__, colorRange, jni_int_vector, 0);
+
     computeMinMaxValues(values, numVertices, &minValue, &maxValue);
 
     /* Z-bounds are not taken into account if either of them is invalid */
@@ -268,6 +274,8 @@ void TriangleMeshFecDataDecomposer::fillColors(char* id, float* buffer, int buff
         }
     }
 
+    releaseGraphicObjectProperty(__GO_Z_BOUNDS__, zBounds, jni_double_vector, 0);
+
     /* To be verified (when reverse z bounds are specified) */
     if (DecompositionUtils::getAbsoluteValue(maxValue - minValue) < DecompositionUtils::getMinDoubleValue())
     {
@@ -314,6 +322,7 @@ void TriangleMeshFecDataDecomposer::fillColors(char* id, float* buffer, int buff
         }
     }
 
+    releaseGraphicObjectProperty(__GO_COLORMAP__, colormap, jni_double_vector, colormapSize);
 }
 
 void TriangleMeshFecDataDecomposer::computeMinMaxValues(double* values, int numValues, double* valueMin, double* valueMax)
index 6de1587..bfd8bec 100644 (file)
@@ -17,6 +17,7 @@ extern "C"
 #include "getGraphicObjectProperty.h"
 #include "graphicObjectProperties.h"
 #include "getScilabJavaVM.h"
+#include <stdio.h>
 }
 
 #include "CallGraphicController.hxx"
@@ -64,7 +65,7 @@ void getGraphicObjectProperty(char const* _pstID, int _iName, _ReturnType_ _retu
         || _iName == __GO_DATA_MODEL_Y_DIMENSIONS__
         || _iName == __GO_DATA_MODEL_MATPLOT_BOUNDS__
         || _iName == __GO_DATA_MODEL_MATPLOT_TYPE__
-               )
+        )
     {
         DataController::getGraphicObjectProperty(_pstID, _iName, _pvData);
         return;
@@ -74,121 +75,152 @@ void getGraphicObjectProperty(char const* _pstID, int _iName, _ReturnType_ _retu
     {
         switch (_returnType)
         {
-            case jni_string:
-            {
-                *(_pvData) = CallGraphicController::getGraphicObjectPropertyAsString(getScilabJavaVM(), _pstID, _iName);
-                return;
-            }
-            case jni_string_vector:
-            {
-                *_pvData = CallGraphicController::getGraphicObjectPropertyAsStringVector(getScilabJavaVM(), _pstID, _iName);
-                return;
-            }
-            case jni_double:
-            {
-                ((double *)*_pvData)[0] = (double)CallGraphicController::getGraphicObjectPropertyAsDouble(getScilabJavaVM(), _pstID, _iName);
-                return;
-            }
-            case jni_double_vector:
-            {
-                *_pvData = CallGraphicController::getGraphicObjectPropertyAsDoubleVector(getScilabJavaVM(), _pstID, _iName);
-                return;
-            }
-            case jni_bool:
-            {
-                ((int *)*_pvData)[0] = (int)CallGraphicController::getGraphicObjectPropertyAsBoolean(getScilabJavaVM(), _pstID, _iName);
-                return;
-            }
-            case jni_bool_vector:
-            {
-                *_pvData = CallGraphicController::getGraphicObjectPropertyAsBooleanVector(getScilabJavaVM(), _pstID, _iName);
-                return;
-            }
-            case jni_int:
-            {
-                ((int *)*_pvData)[0] = CallGraphicController::getGraphicObjectPropertyAsInteger(getScilabJavaVM(), _pstID, _iName);
-                return;
-            }
-            case jni_int_vector:
-            {
-                *_pvData = CallGraphicController::getGraphicObjectPropertyAsIntegerVector(getScilabJavaVM(), _pstID, _iName);
-                return;
-            }
-            default:
-                *_pvData = NULL;
-                return;
-        }
-    }
-    catch (std::exception &e)
-    {
-        e.what();
-        // If we have an exception, return null to scilab to manage error.
-        *_pvData = NULL;
-        return;
-    }
-
-}
-
-
-void releaseGraphicObjectProperty(int _iName, void * _pvData, enum _ReturnType_ _returnType, int numElements)
-{
-
-    /* All the Data model properties have the DATA_MODEL prefix */
-    if (_iName == __GO_DATA_MODEL__)
-    {
-        // passed by reference, do not free them
-        return;
-    }
-
-    switch (_returnType)
-    {
         case jni_string:
         {
-            delete[] (char*) _pvData;
+            *(_pvData) = CallGraphicController::getGraphicObjectPropertyAsString(getScilabJavaVM(), _pstID, _iName);
             return;
         }
         case jni_string_vector:
         {
-            char** data = (char**) _pvData;
-            for (int i = 0; i < numElements; ++i)
-            {
-                delete[] data[i];
-            }
-            delete[] data;
+            *_pvData = CallGraphicController::getGraphicObjectPropertyAsStringVector(getScilabJavaVM(), _pstID, _iName);
             return;
         }
         case jni_double:
         {
-            // passed by value
+            ((double *)*_pvData)[0] = (double)CallGraphicController::getGraphicObjectPropertyAsDouble(getScilabJavaVM(), _pstID, _iName);
             return;
         }
         case jni_double_vector:
         {
-            delete[] (double*) _pvData;
+            *_pvData = CallGraphicController::getGraphicObjectPropertyAsDoubleVector(getScilabJavaVM(), _pstID, _iName);
             return;
         }
         case jni_bool:
         {
-            // passed by value
+            ((int *)*_pvData)[0] = (int)CallGraphicController::getGraphicObjectPropertyAsBoolean(getScilabJavaVM(), _pstID, _iName);
             return;
         }
         case jni_bool_vector:
         {
-            delete[] (int*) _pvData;
+            *_pvData = CallGraphicController::getGraphicObjectPropertyAsBooleanVector(getScilabJavaVM(), _pstID, _iName);
             return;
         }
         case jni_int:
         {
-            // passed by value
+            ((int *)*_pvData)[0] = CallGraphicController::getGraphicObjectPropertyAsInteger(getScilabJavaVM(), _pstID, _iName);
             return;
         }
         case jni_int_vector:
         {
-            delete[] (int*) _pvData;
+            *_pvData = CallGraphicController::getGraphicObjectPropertyAsIntegerVector(getScilabJavaVM(), _pstID, _iName);
             return;
         }
         default:
+            *_pvData = NULL;
             return;
+        }
+    }
+    catch (std::exception &e)
+    {
+        e.what();
+        // If we have an exception, return null to scilab to manage error.
+        *_pvData = NULL;
+        return;
+    }
+
+}
+
+
+void releaseGraphicObjectProperty(int _iName, void * _pvData, enum _ReturnType_ _returnType, int numElements)
+{
+
+    /* All the Data model properties have the DATA_MODEL prefix */
+    if (_iName == __GO_DATA_MODEL__
+        || _iName == __GO_DATA_MODEL_COORDINATES__
+        || _iName == __GO_DATA_MODEL_X__
+        || _iName == __GO_DATA_MODEL_Y__
+        || _iName == __GO_DATA_MODEL_Z__
+        || _iName == __GO_DATA_MODEL_X_COORDINATES_SHIFT__
+        || _iName == __GO_DATA_MODEL_Y_COORDINATES_SHIFT__
+        || _iName == __GO_DATA_MODEL_Z_COORDINATES_SHIFT__
+        || _iName == __GO_DATA_MODEL_X_COORDINATES_SHIFT_SET__
+        || _iName == __GO_DATA_MODEL_Y_COORDINATES_SHIFT_SET__
+        || _iName == __GO_DATA_MODEL_Z_COORDINATES_SHIFT_SET__
+        || _iName == __GO_DATA_MODEL_NUM_ELEMENTS__
+        || _iName == __GO_DATA_MODEL_NUM_ELEMENTS_ARRAY__
+        || _iName == __GO_DATA_MODEL_NUM_VERTICES_PER_GON__
+        || _iName == __GO_DATA_MODEL_NUM_GONS__
+        || _iName == __GO_DATA_MODEL_Z_COORDINATES_SET__
+        || _iName == __GO_DATA_MODEL_COLORS__
+        || _iName == __GO_DATA_MODEL_NUM_COLORS__
+        || _iName == __GO_DATA_MODEL_NUM_VERTICES__
+        || _iName == __GO_DATA_MODEL_NUM_INDICES__
+        || _iName == __GO_DATA_MODEL_INDICES__
+        || _iName == __GO_DATA_MODEL_VALUES__
+        || _iName == __GO_DATA_MODEL_FEC_TRIANGLES__
+        || _iName == __GO_DATA_MODEL_NUM_X__
+        || _iName == __GO_DATA_MODEL_NUM_Y__
+        || _iName == __GO_DATA_MODEL_NUM_Z__
+        || _iName == __GO_DATA_MODEL_GRID_SIZE__
+        || _iName == __GO_DATA_MODEL_X_DIMENSIONS__
+        || _iName == __GO_DATA_MODEL_Y_DIMENSIONS__
+        || _iName == __GO_DATA_MODEL_MATPLOT_BOUNDS__
+        || _iName == __GO_DATA_MODEL_MATPLOT_TYPE__
+        )
+    {
+        // passed by reference, do not free them
+        return;
+    }
+
+    switch (_returnType)
+    {
+    case jni_string:
+    {
+        delete[] (char*) _pvData;
+        return;
+    }
+    case jni_string_vector:
+    {
+        char** data = (char**) _pvData;
+        for (int i = 0; i < numElements; ++i)
+        {
+            delete[] data[i];
+        }
+        delete[] data;
+        return;
+    }
+    case jni_double:
+    {
+        // passed by value
+        return;
+    }
+    case jni_double_vector:
+    {
+        delete[] (double*) _pvData;
+        return;
+    }
+    case jni_bool:
+    {
+        // passed by value
+        return;
+    }
+    case jni_bool_vector:
+    {
+        delete[] (int*) _pvData;
+        return;
+    }
+    case jni_int:
+    {
+        // passed by value
+        return;
+    }
+    case jni_int_vector:
+    {
+        delete[] (int*) _pvData;
+        return;
+    }
+    default:
+        return;
     }
 
 }