You are viewing a plain text version of this content. The canonical link for it is here.
Posted to c-dev@axis.apache.org by Samisa Abeysinghe <sa...@yahoo.com> on 2004/04/14 06:54:31 UTC

Memory leaks - patches

Hi All,
    Following are fixes for some of the memory leaks that I found when debugging Axis C++ clients.
	I think they are serious and need to be fixed as soon as possible.
	I tested the samples after the fixes and they work fine (which suggests that the fixes do not
have any side effects) 
	The files to be updated are... 
	SharedObject.cpp 
	WSDDDeployment.cpp 
	SoapParserXerces.cpp
	SoapDeSerializer.cpp
	SoapSerializer.cpp
Thanks,
Samisa...	
---------------------------------------------	

diff -u ../../original/ws-axis/c/src/engine/SharedObject.cpp ./src/engine/SharedObject.cpp
--- ../../original/ws-axis/c/src/engine/SharedObject.cpp        2004-04-09 11:05:37.000000000
+0600
+++ ./src/engine/SharedObject.cpp       2004-04-12 16:08:29.000000000 +0600
@@ -36,6 +36,7 @@
 #ifdef WIN32
 #else //Linux
     pthread_mutex_destroy (mut);
+    delete mut;
 #endif
 }

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

diff -u ../../original/ws-axis/c/src/wsdd/WSDDDeployment.cpp ./src/wsdd/WSDDDeployment.cpp
--- ../../original/ws-axis/c/src/wsdd/WSDDDeployment.cpp        2004-04-08 19:30:08.000000000
+0600
+++ ./src/wsdd/WSDDDeployment.cpp       2004-04-12 16:13:26.000000000 +0600
@@ -84,6 +84,7 @@
             delete ((*iter2).second);
         }
     }
+    delete m_pLibNameIdMap;
 }

 const WSDDHandlerList* WSDDDeployment::GetGlobalRequestFlowHandlers()

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

diff -u ../../original/ws-axis/c/src/soap/SoapParserXerces.cpp ./src/soap/SoapParserXerces.cpp
--- ../../original/ws-axis/c/src/soap/SoapParserXerces.cpp      2004-04-09 18:43:39.000000000
+0600
+++ ./src/soap/SoapParserXerces.cpp     2004-04-13 11:38:00.000000000 +0600
@@ -31,17 +31,24 @@
     m_nStatus = NULL;
     firstParsed = false;
     m_pParser = XMLReaderFactory::createXMLReader();
+    is = NULL;

 }

 SoapParserXerces::~SoapParserXerces()
 {
     m_nStatus = NULL;
+    if(is)
+        delete is;
+    delete m_pParser;
 }

 int SoapParserXerces::SetInputStream(const Ax_soapstream* pInputStream)
 {
     m_pInputStream = pInputStream;
+    //check if memeory is already allocated for is
+    if(is)
+        delete is;
     is = new SoapInputSource(m_pInputStream->transport.pGetFunct,
         m_pInputStream);
     /* SoapInputSource is(m_pInputStream->transport.pGetFunct,

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

diff -u ../../original/ws-axis/c/src/soap/SoapDeSerializer.cpp ./src/soap/SoapDeSerializer.cpp
--- ../../original/ws-axis/c/src/soap/SoapDeSerializer.cpp      2004-04-09 18:43:39.000000000
+0600
+++ ./src/soap/SoapDeSerializer.cpp     2004-04-14 10:51:03.000000000 +0600
@@ -69,6 +69,10 @@
 SoapDeSerializer::~SoapDeSerializer()
 {
     m_pParser->Init();
+    if (m_pEnv)
+        delete m_pEnv;
+    if(m_pHeader)
+        delete m_pHeader;
     if (m_pParser) delete m_pParser;
 }

@@ -155,6 +159,8 @@
         (0 == strcmp(m_pNode->m_pchNameOrValue,
         SoapKeywordMapping::Map(m_nSoapVersion).pchWords[SKW_HEADER])))
     {
+        if(m_pHeader)
+            delete m_pHeader;
         m_pHeader = new SoapHeader();
         /* Set any attributes/namspaces to the SoapHeader object */

@@ -328,7 +334,10 @@
 {
     if (VERSION_LAST == m_nSoapVersion)
     {
-        GetEnvelope();
+
+        if (m_pEnv)
+               delete m_pEnv;
+        m_pEnv = GetEnvelope();
     }
     return m_nSoapVersion;
 }

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

diff -u ../../original/ws-axis/c/src/soap/SoapSerializer.cpp ./src/soap/SoapSerializer.cpp
--- ../../original/ws-axis/c/src/soap/SoapSerializer.cpp        2004-04-08 18:24:45.000000000
+0600
+++ ./src/soap/SoapSerializer.cpp       2004-04-12 17:05:15.000000000 +0600
@@ -62,6 +62,12 @@
 SoapSerializer::~SoapSerializer()
 {
     if (m_pSoapEnvelope) delete m_pSoapEnvelope;
+
+    for (int x=0; x<m_nMaxBuffersToCreate; x++)
+    {
+        delete [] m_pSZBuffers[x].buffer;
+    }
+    delete [] m_pSZBuffers;
 }

 int SoapSerializer::setSoapEnvelope(SoapEnvelope *pSoapEnvelope)



	
		
__________________________________
Do you Yahoo!?
Yahoo! Tax Center - File online by April 15th
http://taxes.yahoo.com/filing.html

RE: Xerces Paser Memory Leaks - patch

Posted by Samisa Abeysinghe <sa...@yahoo.com>.
Please find the diff file attached.
Thanks,
Samisa...


......................
Hi All,
    I am using C++ clients with Xerces parser and noticed huge amounts of memory leaks, and
managed to find the reason.
    When using the Xerces parser, the XMLString::transcode() method returns a memory buffer that
is expected to be deleted by the caller after use.
    (in other words  XMLString::transcode() calls must have matching XMLString::release() calls)

    I found many memory leaks related to XMLString::transcode() calls in XercesHandler.cpp. (and
fixed them in the patch below)

    Please apply this patch as soon as possible to CVS code for the benefit of those who use the
Xerces parser.

Thanks,
Samisa...	

Here is the patch...

---------------------------------------------
diff -u ../../original/ws-axis/c/src/soap/XercesHandler.cpp src/soap/XercesHandler.cpp
--- ../../original/ws-axis/c/src/soap/XercesHandler.cpp 2004-04-09 19:31:05.000000000 +0600
+++ src/soap/XercesHandler.cpp  2004-04-13 10:24:51.000000000 +0600
@@ -30,31 +30,60 @@
 {
     m_nStatus = AXIS_SUCCESS;
     Nelement = (AnyElement*)malloc(sizeof (AnyElement));
+    //initilize Nelement members
+    Nelement->m_pchNameOrValue = NULL;
+    Nelement->m_pchNamespace = NULL;
+    for( int i = 0; i < MAX_NO_OF_ATTRIBUTES*3; i++)
+        Nelement->m_pchAttributes[i] = NULL;
 }

 XercesHandler::~XercesHandler()
 {
+    //free Nelement members
+    if(Nelement->m_pchNameOrValue)
+        XMLString::release(&const_cast<char *>(Nelement-> m_pchNameOrValue));
+    if(Nelement->m_pchNamespace)
+        XMLString::release(&const_cast<char *>(Nelement-> m_pchNamespace));
+    for( int i = 0; i < MAX_NO_OF_ATTRIBUTES*3; i++)
+    {
+        if(Nelement->m_pchAttributes[i])
+            XMLString::release(&const_cast<char *>(Nelement-> m_pchAttributes[i]));
+    }
+    //free Nelement
+    free(Nelement);
 }

-void XercesHandler::startElement(const XMLCh *const uri,const XMLCh *const
+void XercesHandler::startElement(const XMLCh *const uri,const XMLCh *const
                                  localname,const XMLCh *const qname,
                                  const Attributes &attrs)
 {
     m_pCurrElement = Nelement;
     Nelement->m_type = START_ELEMENT;
+    //free alredy allocated transcodes
+    if(Nelement->m_pchNameOrValue)
+        XMLString::release(&const_cast<char *>(Nelement-> m_pchNameOrValue));
+    if(Nelement->m_pchNamespace)
+        XMLString::release(&const_cast<char *>(Nelement-> m_pchNamespace));
+
     Nelement->m_pchNameOrValue = XMLString::transcode(localname);
     Nelement->m_pchNamespace = XMLString::transcode(uri);
-
+
     unsigned int len = attrs.getLength();
     unsigned int index;
        unsigned int i = 0;
     for (index = 0; index < len*3; index+=3)
-    {
-        Nelement->m_pchAttributes[index] =
+    {
+        if(Nelement->m_pchAttributes[index])
+            XMLString::release(&const_cast<char *>(Nelement-> m_pchAttributes[index]));
+        Nelement->m_pchAttributes[index] =
             XMLString::transcode(attrs.getLocalName(i));
-        Nelement->m_pchAttributes[index+1] =
+        if(Nelement->m_pchAttributes[index])
+            XMLString::release(&const_cast<char *>(Nelement-> m_pchAttributes[index+1]));
+        Nelement->m_pchAttributes[index+1] =
             XMLString::transcode(attrs.getURI(i));
-        Nelement->m_pchAttributes[index+2] =
+        if(Nelement->m_pchAttributes[index])
+            XMLString::release(&const_cast<char *>(Nelement-> m_pchAttributes[index + 2]));
+        Nelement->m_pchAttributes[index+2] =
             XMLString::transcode(attrs.getValue(i));
                i++;
     }
@@ -70,14 +99,16 @@
     return NULL;
 }

-void XercesHandler::characters(const XMLCh* const chars,
+void XercesHandler::characters(const XMLCh* const chars,
                                const unsigned int length)
 {
     m_pCurrElement = Nelement;
     Nelement->m_type = CHARACTER_ELEMENT;
+    if(Nelement->m_pchNameOrValue)
+        XMLString::release(&const_cast<char *>(Nelement-> m_pchNameOrValue));
     Nelement->m_pchNameOrValue = XMLString::transcode(chars);
 }
-void XercesHandler::ignorableWhitespace(const XMLCh* const chars,
+void XercesHandler::ignorableWhitespace(const XMLCh* const chars,
                                         const unsigned int length)
 {}
 void XercesHandler::resetDocument()
@@ -101,25 +132,41 @@
 {
     m_pCurrElement = Nelement;
     Nelement->m_type = END_ELEMENT;
+    if(Nelement->m_pchNameOrValue)
+        XMLString::release(&const_cast<char *>(Nelement-> m_pchNameOrValue));
+    if(Nelement->m_pchNamespace)
+        XMLString::release(&const_cast<char *>(Nelement-> m_pchNamespace));
     Nelement->m_pchNameOrValue = XMLString::transcode(localname);
     Nelement->m_pchNamespace = XMLString::transcode(uri);
+    if(Nelement->m_pchAttributes[0])
+        XMLString::release(&const_cast<char *>(Nelement->m_pchAttributes[0]));
     Nelement->m_pchAttributes[0] = NULL;
 }

-void XercesHandler::startPrefixMapping(const XMLCh* const prefix,
+void XercesHandler::startPrefixMapping(const XMLCh* const prefix,
                                        const XMLCh* const uri)
 {
     Nelement->m_type = START_PREFIX;
+    if(Nelement->m_pchNameOrValue)
+        XMLString::release(&const_cast<char *>(Nelement-> m_pchNameOrValue));
+    if(Nelement->m_pchNamespace)
+        XMLString::release(&const_cast<char *>(Nelement-> m_pchNamespace));
+
     Nelement->m_pchNameOrValue = XMLString::transcode(prefix);
     Nelement->m_pchNamespace = XMLString::transcode(uri);
-    m_NsStack[XMLString::transcode(prefix)] = XMLString::transcode(uri);
+    //do not use transcodein this statement
+    //m_NsStack[XMLString::transcode(prefix)] = XMLString::transcode(uri);
+    m_NsStack[Nelement->m_pchNameOrValue] = Nelement->m_pchNamespace;
+
 }

 void XercesHandler::endPrefixMapping(const XMLCh* const prefix)
 {
     Nelement->m_type = END_PREFIX;
+    if(Nelement->m_pchNameOrValue)
+        XMLString::release(&const_cast<char *>(Nelement-> m_pchNameOrValue));
     Nelement->m_pchNameOrValue = XMLString::transcode(prefix);
-    m_NsStack.erase(XMLString::transcode(prefix));
+    m_NsStack.erase(Nelement->m_pchNameOrValue);
 }

 void XercesHandler::freeElement()


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

RE: Use of STL map (and memory leaks) - patch

Posted by Samisa Abeysinghe <sa...@yahoo.com>.
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

RE: Memory leaks - patches

Posted by Samisa Abeysinghe <sa...@yahoo.com>.
> Could you send the patch diff files as attachments if possible ?. Its
> easier to be applied.

Done.

Samisa...




> -----Original Message-----
> From: Samisa Abeysinghe [mailto:samisa_abeysinghe@yahoo.com] 
> Sent: Wednesday, April 14, 2004 10:55 AM
> To: axis-c-dev@ws.apache.org
> Subject: Memory leaks - patches
> 
> Hi All,
>     Following are fixes for some of the memory leaks that I found when
> debugging Axis C++ clients.
> 	I think they are serious and need to be fixed as soon as
> possible.
> 	I tested the samples after the fixes and they work fine (which
> suggests that the fixes do not
> have any side effects) 
> 	The files to be updated are... 
> 	SharedObject.cpp 
> 	WSDDDeployment.cpp 
> 	SoapParserXerces.cpp
> 	SoapDeSerializer.cpp
> 	SoapSerializer.cpp
> Thanks,
> Samisa...	
> ---------------------------------------------	
> 
> diff -u ../../original/ws-axis/c/src/engine/SharedObject.cpp
> ./src/engine/SharedObject.cpp
> --- ../../original/ws-axis/c/src/engine/SharedObject.cpp
> 2004-04-09 11:05:37.000000000
> +0600
> +++ ./src/engine/SharedObject.cpp       2004-04-12 16:08:29.000000000
> +0600
> @@ -36,6 +36,7 @@
>  #ifdef WIN32
>  #else //Linux
>      pthread_mutex_destroy (mut);
> +    delete mut;
>  #endif
>  }
> 
> ---------------------------------------------
> 
> diff -u ../../original/ws-axis/c/src/wsdd/WSDDDeployment.cpp
> ./src/wsdd/WSDDDeployment.cpp
> --- ../../original/ws-axis/c/src/wsdd/WSDDDeployment.cpp
> 2004-04-08 19:30:08.000000000
> +0600
> +++ ./src/wsdd/WSDDDeployment.cpp       2004-04-12 16:13:26.000000000
> +0600
> @@ -84,6 +84,7 @@
>              delete ((*iter2).second);
>          }
>      }
> +    delete m_pLibNameIdMap;
>  }
> 
>  const WSDDHandlerList* WSDDDeployment::GetGlobalRequestFlowHandlers()
> 
> ---------------------------------------------
> 
> diff -u ../../original/ws-axis/c/src/soap/SoapParserXerces.cpp
> ./src/soap/SoapParserXerces.cpp
> --- ../../original/ws-axis/c/src/soap/SoapParserXerces.cpp
> 2004-04-09 18:43:39.000000000
> +0600
> +++ ./src/soap/SoapParserXerces.cpp     2004-04-13 11:38:00.000000000
> +0600
> @@ -31,17 +31,24 @@
>      m_nStatus = NULL;
>      firstParsed = false;
>      m_pParser = XMLReaderFactory::createXMLReader();
> +    is = NULL;
> 
>  }
> 
>  SoapParserXerces::~SoapParserXerces()
>  {
>      m_nStatus = NULL;
> +    if(is)
> +        delete is;
> +    delete m_pParser;
>  }
> 
>  int SoapParserXerces::SetInputStream(const Ax_soapstream* pInputStream)
>  {
>      m_pInputStream = pInputStream;
> +    //check if memeory is already allocated for is
> +    if(is)
> +        delete is;
>      is = new SoapInputSource(m_pInputStream->transport.pGetFunct,
>          m_pInputStream);
>      /* SoapInputSource is(m_pInputStream->transport.pGetFunct,
> 
> ---------------------------------------------
> 
> diff -u ../../original/ws-axis/c/src/soap/SoapDeSerializer.cpp
> ./src/soap/SoapDeSerializer.cpp
> --- ../../original/ws-axis/c/src/soap/SoapDeSerializer.cpp
> 2004-04-09 18:43:39.000000000
> +0600
> +++ ./src/soap/SoapDeSerializer.cpp     2004-04-14 10:51:03.000000000
> +0600
> @@ -69,6 +69,10 @@
>  SoapDeSerializer::~SoapDeSerializer()
>  {
>      m_pParser->Init();
> +    if (m_pEnv)
> +        delete m_pEnv;
> +    if(m_pHeader)
> +        delete m_pHeader;
>      if (m_pParser) delete m_pParser;
>  }
> 
> @@ -155,6 +159,8 @@
>          (0 == strcmp(m_pNode->m_pchNameOrValue,
>          SoapKeywordMapping::Map(m_nSoapVersion).pchWords[SKW_HEADER])))
>      {
> +        if(m_pHeader)
> +            delete m_pHeader;
>          m_pHeader = new SoapHeader();
>          /* Set any attributes/namspaces to the SoapHeader object */
> 
> @@ -328,7 +334,10 @@
>  {
>      if (VERSION_LAST == m_nSoapVersion)
>      {
> -        GetEnvelope();
> +
> +        if (m_pEnv)
> +               delete m_pEnv;
> +        m_pEnv = GetEnvelope();
>      }
>      return m_nSoapVersion;
>  }
> 
> ---------------------------------------------
> 
> diff -u ../../original/ws-axis/c/src/soap/SoapSerializer.cpp
> ./src/soap/SoapSerializer.cpp
> --- ../../original/ws-axis/c/src/soap/SoapSerializer.cpp
> 2004-04-08 18:24:45.000000000
> +0600
> +++ ./src/soap/SoapSerializer.cpp       2004-04-12 17:05:15.000000000
> +0600
> @@ -62,6 +62,12 @@
>  SoapSerializer::~SoapSerializer()
>  {
>      if (m_pSoapEnvelope) delete m_pSoapEnvelope;
> +
> +    for (int x=0; x<m_nMaxBuffersToCreate; x++)
> +    {
> +        delete [] m_pSZBuffers[x].buffer;
> +    }
> +    delete [] m_pSZBuffers;
>  }
> 
>  int SoapSerializer::setSoapEnvelope(SoapEnvelope *pSoapEnvelope)
> 
> 
> 
> 	
> 		
> __________________________________
> Do you Yahoo!?
> Yahoo! Tax Center - File online by April 15th
> http://taxes.yahoo.com/filing.html
> 
> 


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

RE: Memory leaks - patches

Posted by Susantha Kumara <su...@opensource.lk>.
Hi Samisa,

Could you send the patch diff files as attachments if possible ?. Its
easier to be applied.

Thanks.

-----Original Message-----
From: Samisa Abeysinghe [mailto:samisa_abeysinghe@yahoo.com] 
Sent: Wednesday, April 14, 2004 10:55 AM
To: axis-c-dev@ws.apache.org
Subject: Memory leaks - patches

Hi All,
    Following are fixes for some of the memory leaks that I found when
debugging Axis C++ clients.
	I think they are serious and need to be fixed as soon as
possible.
	I tested the samples after the fixes and they work fine (which
suggests that the fixes do not
have any side effects) 
	The files to be updated are... 
	SharedObject.cpp 
	WSDDDeployment.cpp 
	SoapParserXerces.cpp
	SoapDeSerializer.cpp
	SoapSerializer.cpp
Thanks,
Samisa...	
---------------------------------------------	

diff -u ../../original/ws-axis/c/src/engine/SharedObject.cpp
./src/engine/SharedObject.cpp
--- ../../original/ws-axis/c/src/engine/SharedObject.cpp
2004-04-09 11:05:37.000000000
+0600
+++ ./src/engine/SharedObject.cpp       2004-04-12 16:08:29.000000000
+0600
@@ -36,6 +36,7 @@
 #ifdef WIN32
 #else //Linux
     pthread_mutex_destroy (mut);
+    delete mut;
 #endif
 }

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

diff -u ../../original/ws-axis/c/src/wsdd/WSDDDeployment.cpp
./src/wsdd/WSDDDeployment.cpp
--- ../../original/ws-axis/c/src/wsdd/WSDDDeployment.cpp
2004-04-08 19:30:08.000000000
+0600
+++ ./src/wsdd/WSDDDeployment.cpp       2004-04-12 16:13:26.000000000
+0600
@@ -84,6 +84,7 @@
             delete ((*iter2).second);
         }
     }
+    delete m_pLibNameIdMap;
 }

 const WSDDHandlerList* WSDDDeployment::GetGlobalRequestFlowHandlers()

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

diff -u ../../original/ws-axis/c/src/soap/SoapParserXerces.cpp
./src/soap/SoapParserXerces.cpp
--- ../../original/ws-axis/c/src/soap/SoapParserXerces.cpp
2004-04-09 18:43:39.000000000
+0600
+++ ./src/soap/SoapParserXerces.cpp     2004-04-13 11:38:00.000000000
+0600
@@ -31,17 +31,24 @@
     m_nStatus = NULL;
     firstParsed = false;
     m_pParser = XMLReaderFactory::createXMLReader();
+    is = NULL;

 }

 SoapParserXerces::~SoapParserXerces()
 {
     m_nStatus = NULL;
+    if(is)
+        delete is;
+    delete m_pParser;
 }

 int SoapParserXerces::SetInputStream(const Ax_soapstream* pInputStream)
 {
     m_pInputStream = pInputStream;
+    //check if memeory is already allocated for is
+    if(is)
+        delete is;
     is = new SoapInputSource(m_pInputStream->transport.pGetFunct,
         m_pInputStream);
     /* SoapInputSource is(m_pInputStream->transport.pGetFunct,

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

diff -u ../../original/ws-axis/c/src/soap/SoapDeSerializer.cpp
./src/soap/SoapDeSerializer.cpp
--- ../../original/ws-axis/c/src/soap/SoapDeSerializer.cpp
2004-04-09 18:43:39.000000000
+0600
+++ ./src/soap/SoapDeSerializer.cpp     2004-04-14 10:51:03.000000000
+0600
@@ -69,6 +69,10 @@
 SoapDeSerializer::~SoapDeSerializer()
 {
     m_pParser->Init();
+    if (m_pEnv)
+        delete m_pEnv;
+    if(m_pHeader)
+        delete m_pHeader;
     if (m_pParser) delete m_pParser;
 }

@@ -155,6 +159,8 @@
         (0 == strcmp(m_pNode->m_pchNameOrValue,
         SoapKeywordMapping::Map(m_nSoapVersion).pchWords[SKW_HEADER])))
     {
+        if(m_pHeader)
+            delete m_pHeader;
         m_pHeader = new SoapHeader();
         /* Set any attributes/namspaces to the SoapHeader object */

@@ -328,7 +334,10 @@
 {
     if (VERSION_LAST == m_nSoapVersion)
     {
-        GetEnvelope();
+
+        if (m_pEnv)
+               delete m_pEnv;
+        m_pEnv = GetEnvelope();
     }
     return m_nSoapVersion;
 }

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

diff -u ../../original/ws-axis/c/src/soap/SoapSerializer.cpp
./src/soap/SoapSerializer.cpp
--- ../../original/ws-axis/c/src/soap/SoapSerializer.cpp
2004-04-08 18:24:45.000000000
+0600
+++ ./src/soap/SoapSerializer.cpp       2004-04-12 17:05:15.000000000
+0600
@@ -62,6 +62,12 @@
 SoapSerializer::~SoapSerializer()
 {
     if (m_pSoapEnvelope) delete m_pSoapEnvelope;
+
+    for (int x=0; x<m_nMaxBuffersToCreate; x++)
+    {
+        delete [] m_pSZBuffers[x].buffer;
+    }
+    delete [] m_pSZBuffers;
 }

 int SoapSerializer::setSoapEnvelope(SoapEnvelope *pSoapEnvelope)



	
		
__________________________________
Do you Yahoo!?
Yahoo! Tax Center - File online by April 15th
http://taxes.yahoo.com/filing.html