axis-c-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Samisa Abeysinghe <samisa_abeysin...@yahoo.com>
Subject RE: Use of STL map (and memory leaks) - patch
Date Thu, 22 Apr 2004 07:04:13 GMT
Please find diff files attached.
Thanks,
Samisa



..........................
Hi All,
    The use of STL map seems to cause memeory leaks (it leaves 'reachable memory' behind after
client terminates)
	It is quite possible to do without the STL map in some cases. I have done this for
SoapKeywordMapping. (see patch below)
	In cases it is difficult to replace maps with arrays (as an exampel when key is a string)
we may
have to look for alternatives.
	
	Is it possible to replace STL map with our own map? (I think to do this without templates,
we
have to stick to string keys)
	
	I also fixed some memory leaks in SoapKeywordMapping code. Need to call
SoapKeywordMapping::uninitialize () from Axis.cpp uninitialize_module() to make this effextive.

	Please update the CVS with the patch. (SoapKeywordMapping.h, SoapKeywordMapping.cpp and Axis.cpp)
Thanks,
Samisa...	

Here is the patch...

---------------------------------------------

diff -u ../../original/ws-axis/c/src/soap/SoapKeywordMapping.h ./src/soap/SoapKeywordMapping.h
--- ../../original/ws-axis/c/src/soap/SoapKeywordMapping.h      2004-04-08 16:42:47.000000000
+0600
+++ ./src/soap/SoapKeywordMapping.h     2004-04-13 15:57:01.000000000 +0600
@@ -17,6 +17,7 @@
 #if !defined(AXIS_SOAPKEYWORDMAPPING_H__INCLUDED_)
 #define AXIS_SOAPKEYWORDMAPPING_H__INCLUDED_

+#include "../common/AxisUtils.h"
 #include <axis/server/SoapEnvVersions.h>
 #include <map>

@@ -43,11 +44,13 @@
     SoapKeywordMapping();
     virtual ~SoapKeywordMapping();
 private:
-    static map<int, SoapKeywordStruct> m_Map;
+    //static map<int, SoapKeywordStruct> m_Map;
+    static SoapKeywordStruct m_Map[VERSION_LAST];
     static volatile bool m_bInit;
 public:
     static void Initialize();
-    static const SoapKeywordStruct& Map(int nVersion);
+    static void uninitialize();
+    static const SoapKeywordStruct& Map(int nVersion);
 };

 #endif

 --------------------------------------------

diff -u ../../original/ws-axis/c/src/soap/SoapKeywordMapping.cpp ./src/soap/SoapKeywordMapping.cpp
--- ../../original/ws-axis/c/src/soap/SoapKeywordMapping.cpp    2004-04-08 15:40:27.000000000
+0600
+++ ./src/soap/SoapKeywordMapping.cpp   2004-04-13 15:59:01.000000000 +0600
@@ -21,9 +21,10 @@

 #include "SoapKeywordMapping.h"
 #include <axis/server/Attribute.h>
-#include "../common/AxisUtils.h"
+//#include "../common/AxisUtils.h"

-map<int, SoapKeywordStruct> SoapKeywordMapping::m_Map;
+//map<int, SoapKeywordStruct> SoapKeywordMapping::m_Map;
+SoapKeywordStruct SoapKeywordMapping::m_Map[VERSION_LAST];
 volatile bool SoapKeywordMapping::m_bInit = false;

 #define __TRC(X) AxisUtils::ToAxisXMLCh(X)
@@ -35,7 +36,7 @@

 SoapKeywordMapping::~SoapKeywordMapping()
 {
-
+//    m_Map.clear();
 }

 void SoapKeywordMapping::Initialize()
@@ -44,9 +45,9 @@
     {
         for (int sv = SOAP_VER_1_1; sv < VERSION_LAST; sv++)
         {
-            m_Map[sv].pchNamespaceUri =
+            m_Map[sv].pchNamespaceUri =
                 __TRC(gs_SoapEnvVersionsStruct[sv].pchNamespaceUri);
-            m_Map[sv].pchPrefix =
+            m_Map[sv].pchPrefix =
                 __TRC(gs_SoapEnvVersionsStruct[sv].pchPrefix);
             for (int sw = SKW_ENVELOPE; sw < SOAP_WORDS_LAST; sw++)
             {
@@ -72,6 +73,21 @@
     }
 }

+void SoapKeywordMapping::uninitialize()
+{
+    if (m_bInit)
+    {
+        /* soap 1.1 envelop attributes */
+        delete m_Map[SOAP_VER_1_1].pEnv;
+        delete m_Map[SOAP_VER_1_1].pXsi;
+        delete m_Map[SOAP_VER_1_1].pXsd;
+        delete m_Map[SOAP_VER_1_2].pEnv;
+        delete m_Map[SOAP_VER_1_2].pXsi;
+        delete m_Map[SOAP_VER_1_2].pXsd;
+        m_bInit = false;
+    }
+}
+
 const SoapKeywordStruct& SoapKeywordMapping::Map(int nVersion)
 {
     return m_Map[nVersion];

--------------------------------------------------------
diff -u ../../original/ws-axis/c/src/engine/Axis.cpp src/engine/Axis.cpp
--- ../../original/ws-axis/c/src/engine/Axis.cpp        2004-04-08 18:07:54.000000000 +0600
+++ src/engine/Axis.cpp 2004-04-13 11:22:27.000000000 +0600
@@ -316,8 +316,11 @@

 extern "C" int uninitialize_module ()
 {
-    // XMLPlatformUtils::Terminate();
+#ifdef USE_XERCES_PARSER
+    XMLPlatformUtils::Terminate ();
+#endif
     ModuleUnInitialize ();
+    SoapKeywordMapping::uninitialize ();
     return AXIS_SUCCESS;
 }


	
		
__________________________________
Do you Yahoo!?
Yahoo! Photos: High-quality 4x6 digital prints for 25
http://photos.yahoo.com/ph/print_splash
Mime
View raw message