Fix a memory leak in sci_xclick.
Jean-baptiste Silvy [Mon, 25 Aug 2008 14:47:51 +0000 (14:47 +0000)]
scilab/modules/graphics/includes/BasicAlgos.h
scilab/modules/graphics/sci_gateway/c/sci_xclick.c
scilab/modules/graphics/src/c/BasicAlgos.c
scilab/modules/renderer/Makefile.am
scilab/modules/renderer/includes/rendererBasicAlgos.h [new file with mode: 0644]
scilab/modules/renderer/renderer.vcproj
scilab/modules/renderer/renderer_header.def
scilab/modules/renderer/src/cpp/rendererBasicAlgos.cpp [new file with mode: 0644]

index 5a9e33d..f89e7dc 100644 (file)
@@ -86,6 +86,11 @@ double * createNewArrayFromSource( int destSize, const double src[], int srcSize
 void destroyStringArray( char * src[], int nbStrings ) ;
 
 /**
+ * Free a string allocated by new
+ */
+void destroyCppString(char * string);
+
+/**
  * allocate a copy of a double array
  */
 double * createDoubleArrayCopy( const double src[], int nbElement ) ;
index 390c27a..0615a71 100644 (file)
@@ -29,6 +29,8 @@
 #include "ObjectSelection.h"
 #include "WindowList.h"
 #include "axesScale.h"
+#include "BasicAlgos.h"
+
 /*--------------------------------------------------------------------------*/
 int sci_xclick(char *fname,unsigned long fname_len)
 {
@@ -117,6 +119,9 @@ int sci_xclick(char *fname,unsigned long fname_len)
     CreateVar(Rhs+5,STRING_DATATYPE,&istr,&one,&rep); 
     strncpy(cstk(rep),menuCallback,istr);
   }
+
+  destroyCppString(menuCallback);
+
   return 0;
 }
 /*--------------------------------------------------------------------------*/
index 59fadad..878290f 100644 (file)
@@ -20,6 +20,7 @@
 #include "BasicAlgos.h"
 #include "MALLOC.h"
 #include "core_math.h"
+#include "rendererBasicAlgos.h"
 
 /*------------------------------------------------------------------------*/
 double sciFindStPosMin( double x[], int n )
@@ -177,6 +178,11 @@ void destroyStringArray( char * src[], int nbStrings )
   FREE( src ) ;
 }
 /*--------------------------------------------------------------------------*/
+void destroyCppString(char * string)
+{
+  destroyRendererString(string);
+}
+/*--------------------------------------------------------------------------*/
 double * createDoubleArrayCopy( const double src[], int nbElement )
 {
   double * res = MALLOC( nbElement * sizeof(double) ) ;
index 0f2df1b..c151c7f 100644 (file)
@@ -258,7 +258,8 @@ src/cpp/subwinDrawing/AutomaticSubticksComputer.cpp \
 src/cpp/subwinDrawing/UserDefLogSubticksComputer.cpp \
 src/cpp/subwinDrawing/UserDefinedSubticksComputer.cpp \
 src/cpp/axesDrawing/AxesSubticksComputer.cpp \
-src/jni/GiwsException.cpp
+src/jni/GiwsException.cpp \
+src/cpp/rendererBasicAlgos.cpp
 
 # List of the gateway c files
 GATEWAY_C_SOURCES = sci_gateway/c/gw_renderer.c
@@ -374,7 +375,8 @@ includes/GetJavaProperty.h \
 includes/GraphicSynchronizerInterface.h \
 includes/SetJavaProperty.h \
 includes/JavaInteraction.h \
-includes/RendererFontManager.h
+includes/RendererFontManager.h \
+includes/rendererBasicAlgos.h
 
 
 
diff --git a/scilab/modules/renderer/includes/rendererBasicAlgos.h b/scilab/modules/renderer/includes/rendererBasicAlgos.h
new file mode 100644 (file)
index 0000000..e667141
--- /dev/null
@@ -0,0 +1,31 @@
+/*
+ * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+ * Copyright (C) 2008 - INRIA - Jean-Baptiste Silvy 
+ * desc : Several C++ functions that parform some basic operations
+ * 
+ * This file must be used under the terms of the CeCILL.
+ * This source file is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution.  The terms
+ * are also available at    
+ * http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+ *
+ */
+
+#ifndef _RENDERER_BASIC_ALGOS_HXX_
+#define _RENDERER_BASIC_ALGOS_HXX_
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * Destroy a character string allocated by c++ new.
+ */
+void destroyRendererString(char * string);
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _RENDERER_BASIC_ALGOS_HXX_ */
index 4fdb1c8..0c590f3 100644 (file)
                        />
                </Configuration>
                <Configuration
-                       Name="Debug|x64"
+                       Name="Release|Win32"
                        OutputDirectory="$(SolutionDir)$(ConfigurationName)"
                        IntermediateDirectory="$(ConfigurationName)"
                        ConfigurationType="2"
                        CharacterSet="2"
+                       WholeProgramOptimization="0"
                        >
                        <Tool
                                Name="VCPreBuildEventTool"
                        />
                        <Tool
                                Name="VCMIDLTool"
-                               TargetEnvironment="3"
                        />
                        <Tool
                                Name="VCCLCompilerTool"
-                               Optimization="0"
+                               InlineFunctionExpansion="1"
+                               FavorSizeOrSpeed="1"
+                               WholeProgramOptimization="false"
                                AdditionalIncludeDirectories="includes;../jvm/includes;../localization/includes;../graphics/includes;../graphics/includes/handleDrawing;../graphic_export/includes;src/cpp;../../libs/doublylinkedlist/includes;../../libs/MALLOC/includes;../core/includes;../windows_tools/includes;../output_stream/includes;../../java/jdk/include;../../java/jdk/include/win32;src/jni;../../libs/intl"
-                               PreprocessorDefinitions="_CRT_SECURE_NO_DEPRECATE;WITH_TK;FORDLL;_DEBUG;_WINDOWS;_USRDLL;RENDERER_EXPORTS;STATIC_LINKED"
-                               MinimalRebuild="true"
-                               BasicRuntimeChecks="0"
-                               RuntimeLibrary="1"
+                               PreprocessorDefinitions="_CRT_SECURE_NO_DEPRECATE;WITH_TK;FORDLL;NDEBUG;_WINDOWS;_USRDLL;RENDERER_EXPORTS;STATIC_LINKED"
+                               StringPooling="true"
+                               RuntimeLibrary="0"
+                               EnableEnhancedInstructionSet="1"
                                UsePrecompiledHeader="0"
                                WarningLevel="3"
                                Detect64BitPortabilityProblems="false"
                        <Tool
                                Name="VCPreLinkEventTool"
                                Description="Make dependencies"
-                               CommandLine="lib /DEF:&quot;$(InputDir)LibScilab_Import.def&quot; /SUBSYSTEM:WINDOWS /MACHINE:X64 /OUT:&quot;$(InputDir)LibScilab.lib&quot; 1&gt;NUL 2&gt;NUL&#x0D;&#x0A;lib /DEF:&quot;$(InputDir)graphics_Import.def&quot; /SUBSYSTEM:WINDOWS /MACHINE:X64 /OUT:&quot;$(InputDir)graphics.lib&quot; 1&gt;NUL 2&gt;NUL&#x0D;&#x0A;lib /DEF:&quot;$(InputDir)scilab_windows_Import.def&quot; /SUBSYSTEM:WINDOWS /MACHINE:X64 /OUT:&quot;$(InputDir)scilab_windows.lib&quot; 1&gt;NUL 2&gt;NUL&#x0D;&#x0A;cd $(IntDir) &gt;nul&#x0D;&#x0A;for %%f in (*.obj) do  ..\..\..\bin\dumpexts -o %%~nf.def -n scirenderer.dll %%f &gt;nul&#x0D;&#x0A;copy *.def renderertmp.def &gt;nul&#x0D;&#x0A;copy ..\renderer_header.def+renderertmp.def  ..\renderer.def &gt;nul&#x0D;&#x0A;del *.def &gt;nul&#x0D;&#x0A;cd .. &gt;nul&#x0D;&#x0A;"
+                               CommandLine="lib /DEF:&quot;$(InputDir)LibScilab_Import.def&quot; /SUBSYSTEM:WINDOWS /MACHINE:X86 /OUT:&quot;$(InputDir)LibScilab.lib&quot; 1&gt;NUL 2&gt;NUL&#x0D;&#x0A;lib /DEF:&quot;$(InputDir)graphics_Import.def&quot; /SUBSYSTEM:WINDOWS /MACHINE:X86 /OUT:&quot;$(InputDir)graphics.lib&quot; 1&gt;NUL 2&gt;NUL&#x0D;&#x0A;lib /DEF:&quot;$(InputDir)scilab_windows_Import.def&quot; /SUBSYSTEM:WINDOWS /MACHINE:X86 /OUT:&quot;$(InputDir)scilab_windows.lib&quot; 1&gt;NUL 2&gt;NUL&#x0D;&#x0A;cd $(IntDir) &gt;nul&#x0D;&#x0A;for %%f in (*.obj) do  ..\..\..\bin\dumpexts -o %%~nf.def -n scirenderer.dll %%f &gt;nul&#x0D;&#x0A;copy *.def renderertmp.def &gt;nul&#x0D;&#x0A;copy ..\renderer_header.def+renderertmp.def  ..\renderer.def &gt;nul&#x0D;&#x0A;del *.def &gt;nul&#x0D;&#x0A;cd .. &gt;nul&#x0D;&#x0A;"
                        />
                        <Tool
                                Name="VCLinkerTool"
                                OutputFile="../../bin/scirenderer.dll"
                                LinkIncremental="1"
                                ModuleDefinitionFile="renderer.def"
-                               GenerateDebugInformation="true"
+                               GenerateDebugInformation="false"
                                SubSystem="2"
+                               OptimizeReferences="2"
+                               EnableCOMDATFolding="2"
+                               LinkTimeCodeGeneration="0"
                                RandomizedBaseAddress="1"
                                DataExecutionPrevention="0"
-                               TargetMachine="17"
+                               ImportLibrary="../../bin/scirenderer.lib"
+                               TargetMachine="1"
                                CLRUnmanagedCodeCheck="true"
                        />
                        <Tool
                        />
                </Configuration>
                <Configuration
-                       Name="Release|Win32"
+                       Name="Debug|x64"
                        OutputDirectory="$(SolutionDir)$(ConfigurationName)"
                        IntermediateDirectory="$(ConfigurationName)"
                        ConfigurationType="2"
                        CharacterSet="2"
-                       WholeProgramOptimization="0"
                        >
                        <Tool
                                Name="VCPreBuildEventTool"
                        />
                        <Tool
                                Name="VCMIDLTool"
+                               TargetEnvironment="3"
                        />
                        <Tool
                                Name="VCCLCompilerTool"
-                               InlineFunctionExpansion="1"
-                               FavorSizeOrSpeed="1"
-                               WholeProgramOptimization="false"
+                               Optimization="0"
                                AdditionalIncludeDirectories="includes;../jvm/includes;../localization/includes;../graphics/includes;../graphics/includes/handleDrawing;../graphic_export/includes;src/cpp;../../libs/doublylinkedlist/includes;../../libs/MALLOC/includes;../core/includes;../windows_tools/includes;../output_stream/includes;../../java/jdk/include;../../java/jdk/include/win32;src/jni;../../libs/intl"
-                               PreprocessorDefinitions="_CRT_SECURE_NO_DEPRECATE;WITH_TK;FORDLL;NDEBUG;_WINDOWS;_USRDLL;RENDERER_EXPORTS;STATIC_LINKED"
-                               StringPooling="true"
-                               RuntimeLibrary="0"
-                               EnableEnhancedInstructionSet="1"
+                               PreprocessorDefinitions="_CRT_SECURE_NO_DEPRECATE;WITH_TK;FORDLL;_DEBUG;_WINDOWS;_USRDLL;RENDERER_EXPORTS;STATIC_LINKED"
+                               MinimalRebuild="true"
+                               BasicRuntimeChecks="0"
+                               RuntimeLibrary="1"
                                UsePrecompiledHeader="0"
                                WarningLevel="3"
                                Detect64BitPortabilityProblems="false"
                        <Tool
                                Name="VCPreLinkEventTool"
                                Description="Make dependencies"
-                               CommandLine="lib /DEF:&quot;$(InputDir)LibScilab_Import.def&quot; /SUBSYSTEM:WINDOWS /MACHINE:X86 /OUT:&quot;$(InputDir)LibScilab.lib&quot; 1&gt;NUL 2&gt;NUL&#x0D;&#x0A;lib /DEF:&quot;$(InputDir)graphics_Import.def&quot; /SUBSYSTEM:WINDOWS /MACHINE:X86 /OUT:&quot;$(InputDir)graphics.lib&quot; 1&gt;NUL 2&gt;NUL&#x0D;&#x0A;lib /DEF:&quot;$(InputDir)scilab_windows_Import.def&quot; /SUBSYSTEM:WINDOWS /MACHINE:X86 /OUT:&quot;$(InputDir)scilab_windows.lib&quot; 1&gt;NUL 2&gt;NUL&#x0D;&#x0A;cd $(IntDir) &gt;nul&#x0D;&#x0A;for %%f in (*.obj) do  ..\..\..\bin\dumpexts -o %%~nf.def -n scirenderer.dll %%f &gt;nul&#x0D;&#x0A;copy *.def renderertmp.def &gt;nul&#x0D;&#x0A;copy ..\renderer_header.def+renderertmp.def  ..\renderer.def &gt;nul&#x0D;&#x0A;del *.def &gt;nul&#x0D;&#x0A;cd .. &gt;nul&#x0D;&#x0A;"
+                               CommandLine="lib /DEF:&quot;$(InputDir)LibScilab_Import.def&quot; /SUBSYSTEM:WINDOWS /MACHINE:X64 /OUT:&quot;$(InputDir)LibScilab.lib&quot; 1&gt;NUL 2&gt;NUL&#x0D;&#x0A;lib /DEF:&quot;$(InputDir)graphics_Import.def&quot; /SUBSYSTEM:WINDOWS /MACHINE:X64 /OUT:&quot;$(InputDir)graphics.lib&quot; 1&gt;NUL 2&gt;NUL&#x0D;&#x0A;lib /DEF:&quot;$(InputDir)scilab_windows_Import.def&quot; /SUBSYSTEM:WINDOWS /MACHINE:X64 /OUT:&quot;$(InputDir)scilab_windows.lib&quot; 1&gt;NUL 2&gt;NUL&#x0D;&#x0A;cd $(IntDir) &gt;nul&#x0D;&#x0A;for %%f in (*.obj) do  ..\..\..\bin\dumpexts -o %%~nf.def -n scirenderer.dll %%f &gt;nul&#x0D;&#x0A;copy *.def renderertmp.def &gt;nul&#x0D;&#x0A;copy ..\renderer_header.def+renderertmp.def  ..\renderer.def &gt;nul&#x0D;&#x0A;del *.def &gt;nul&#x0D;&#x0A;cd .. &gt;nul&#x0D;&#x0A;"
                        />
                        <Tool
                                Name="VCLinkerTool"
                                OutputFile="../../bin/scirenderer.dll"
                                LinkIncremental="1"
                                ModuleDefinitionFile="renderer.def"
-                               GenerateDebugInformation="false"
+                               GenerateDebugInformation="true"
                                SubSystem="2"
-                               OptimizeReferences="2"
-                               EnableCOMDATFolding="2"
-                               LinkTimeCodeGeneration="0"
                                RandomizedBaseAddress="1"
                                DataExecutionPrevention="0"
-                               ImportLibrary="../../bin/scirenderer.lib"
-                               TargetMachine="1"
+                               TargetMachine="17"
                                CLRUnmanagedCodeCheck="true"
                        />
                        <Tool
                                >
                        </File>
                        <File
+                               RelativePath=".\src\cpp\rendererBasicAlgos.cpp"
+                               >
+                       </File>
+                       <File
                                RelativePath=".\src\cpp\RendererFontManager.cpp"
                                >
                        </File>
                                >
                        </File>
                        <File
+                               RelativePath=".\includes\rendererBasicAlgos.h"
+                               >
+                       </File>
+                       <File
                                RelativePath=".\includes\RendererFontManager.h"
                                >
                        </File>
index 8619641..80aba12 100644 (file)
@@ -41,5 +41,6 @@ sciGetJava2dViewCoordinates
 javaRubberBox
 sciGetJavaIsAbleToCreateWindow
 sciGetJavaBoundingBox
+destroyRendererString
 ; --------------------------------------- 
 
diff --git a/scilab/modules/renderer/src/cpp/rendererBasicAlgos.cpp b/scilab/modules/renderer/src/cpp/rendererBasicAlgos.cpp
new file mode 100644 (file)
index 0000000..ff58efa
--- /dev/null
@@ -0,0 +1,22 @@
+/*
+ * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+ * Copyright (C) 2008 - INRIA - Jean-Baptiste Silvy 
+ * desc : Several C++ functions that parform some basic operations
+ * 
+ * This file must be used under the terms of the CeCILL.
+ * This source file is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution.  The terms
+ * are also available at    
+ * http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+ *
+ */
+
+
+#include "rendererBasicAlgos.h"
+
+/*--------------------------------------------------------------------------*/
+void destroyRendererString(char * string)
+{
+  delete[] string;
+}  
+/*--------------------------------------------------------------------------*/