You are viewing a plain text version of this content. The canonical link for it is here.
Posted to c-dev@xerces.apache.org by Nedelcho Stanev <ne...@lta-bg.com> on 2004/04/13 12:27:52 UTC

Memory leaks and crash with MemBufInputSource

Hello All,

I have problem using xerces 2.5.0 compiled with Visual Studio .Net on
Windows 2000 Pro.
I have this small source :

int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
{
 XMLPlatformUtils::Initialize();
 int nRetCode = 0;
 CString mem = "<?xml version=\"1.0\" standalone=\"no\" ?><Operation
type=\"CheckID\"></Operation>";
#ifdef _DEBUG
   CMemoryState oldMemState, newMemState, diffMemState;
   oldMemState.Checkpoint();
#endif
 MemBufInputSource memBufIS((const XMLByte*)mem.GetBuffer(),
mem.GetLength(), "test", false);
 XercesDOMParser *domParser  = new XercesDOMParser;
 domParser->parse(memBufIS);
 delete domParser;
 domParser = NULL;
#ifdef _DEBUG
   newMemState.Checkpoint();
   if( diffMemState.Difference( oldMemState, newMemState ) )
   {
      TRACE( "Memory leaked!\n" );
   diffMemState.DumpStatistics();
   }
#endif
 XMLPlatformUtils::Terminate();
 return nRetCode;
}

Using CMemoryState  in this code, i see that after deleting of parser i
still have memory leaks:

>> Memory leaked!
>> 0 bytes in 0 Free Blocks.
>> 660 bytes in 31 Normal Blocks.
>> 0 bytes in 0 CRT Blocks.
>> 0 bytes in 0 Ignore Blocks.
>> 0 bytes in 0 Client Blocks.
>> Largest number used: 208270 bytes.
>> Total allocations: 208270 bytes.

I try lot of ways to do this parsing from buffer, but without any success, i
still have this leaks
and second, when i quit from program where desctructor of MemBufInputSource
is executed
program crash in destructor of InputSource on this place :

fMemoryManager->deallocate(fEncoding);

where fEncoding is NULL.I think will be better if before to try to release
memory some check
will be performed , like

if(fEncoding)
    fMemoryManager->deallocate(fEncoding);

about problem with memory leak i still didn't look where is the prob, so
if someone can help i will be happy :)

decho



Re: Weird getFirstChild() node behavior

Posted by Sylvain Duval <du...@jouve.fr>.
Hi Monica,

The values of nodeName, nodeValue, and attributes vary according to the 
node type as follows:
http://xml.apache.org/xerces-c/apiDocs/classDOMNode.html#z229_0
(Look at Detailed Description)

For a DOMText getNodeName return #Text but getNodeValue return the Text.

Sylvain.

At 14:57 13/04/04 -0700, you wrote:
>Hi all,
>
>I have a simple XML string: <d><id>1</id></d>
>After parsing this string, I wrote a function to
>traverse this DOM tree to get the node name/pairs.
>I'm running into a weird problem when I try to get the
>node name of <d>'s child (which is "id"):
>
>Note: In the following code, the current node being
>processed is <d>.
>
>(1) This piece of code works, and the print out is
>"id":
>DOMNodeList *children = node->getChildNodes();
>cout <<
>XMLString::transcode((children->item(1))->getNodeName())
><< endl;
>
>(2) This code does not work, and the print out is
>"#text":
>cout <<
>XMLString::transcode((node->getFirstChild())->getNodeName())
><< endl;
>
>Does anyone know why the "getFirstChild()" function
>does not return the expected results?  Is this a bug?
>
>Thanks for your time and help.
>
>Regards,
>Monica
>
>
>
>
>
>__________________________________
>Do you Yahoo!?
>Yahoo! Tax Center - File online by April 15th
>http://taxes.yahoo.com/filing.html
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: xerces-c-dev-unsubscribe@xml.apache.org
>For additional commands, e-mail: xerces-c-dev-help@xml.apache.org


Weird getFirstChild() node behavior

Posted by Monica Lau <ml...@yahoo.com>.
Hi all,

I have a simple XML string: <d><id>1</id></d>
After parsing this string, I wrote a function to
traverse this DOM tree to get the node name/pairs. 
I'm running into a weird problem when I try to get the
node name of <d>'s child (which is "id"):

Note: In the following code, the current node being
processed is <d>.

(1) This piece of code works, and the print out is
"id":
DOMNodeList *children = node->getChildNodes();
cout <<
XMLString::transcode((children->item(1))->getNodeName())
<< endl;

(2) This code does not work, and the print out is
"#text":
cout <<
XMLString::transcode((node->getFirstChild())->getNodeName())
<< endl;

Does anyone know why the "getFirstChild()" function
does not return the expected results?  Is this a bug?

Thanks for your time and help.

Regards,
Monica



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

---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-c-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-c-dev-help@xml.apache.org


Re: Memory question

Posted by Gareth Reakes <ga...@parthenoncomputing.com>.
Hi,

> When I do a DOMNode* pnodetoRelease = pNode->removeChild(*it);
>
> Is the pnodetoRelease still released when I call the DOMDocument release
> method  or it is really orphaned?

It is still released.

Gareth


-- 
Gareth Reakes, Managing Director      Parthenon Computing
+44-1865-811184                  http://www.parthcomp.com

---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-c-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-c-dev-help@xml.apache.org


Re: Memory question

Posted by Sylvain Duval <du...@jouve.fr>.
Thanks, so you mean Xerces internally reallocate new buffers...

Other question about removeChild ... just to be sure ...

When I do a DOMNode* pnodetoRelease = pNode->removeChild(*it);

Is the pnodetoRelease still released when I call the DOMDocument release 
method  or it is really orphaned?


At 14:51 13/04/04 +0100, you wrote:
>Hi,
>         you have to delete it.
>
>Gareth
>
>On Tue, 13 Apr 2004, Sylvain Duval wrote:
>
> > Hi all,
> >
> > Small question about memory management :
> >
> > When I do a setAttribute like this on a DOMElement :
> >
> > XMLCh* Name;
> > chName = XMLString::transcode("synchro");
> >
> > XMLCh* chValue;
> > chValue = XMLString::transcode("attValue");
> >
> > ((DOMElement*)pNode)->setAttribute(chName, chValue);
> >
> > Do I have to release the XMLCh* or this memory will be used in the DOM tree
> > in memory?
> >
> > XMLString::release(&chName);  ???
> > XMLString::release(&chValue); ???
> >
> > Thanks for your help.
> >
> > Sylvain.
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: xerces-c-dev-unsubscribe@xml.apache.org
> > For additional commands, e-mail: xerces-c-dev-help@xml.apache.org
> >
> >
>
>--
>Gareth Reakes, Managing Director            +44-1865-811184
>Parthenon Computing                http://www.parthcomp.com
>
>
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: xerces-c-dev-unsubscribe@xml.apache.org
>For additional commands, e-mail: xerces-c-dev-help@xml.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-c-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-c-dev-help@xml.apache.org


Re: Memory question

Posted by Nedelcho Stanev <ne...@lta-bg.com>.
yep
you need to release it

decho
----- Original Message -----
From: "Sylvain Duval" <du...@jouve.fr>
To: <xe...@xml.apache.org>
Sent: Tuesday, April 13, 2004 4:14 PM
Subject: Memory question


> Hi all,
>
> Small question about memory management :
>
> When I do a setAttribute like this on a DOMElement :
>
> XMLCh* Name;
> chName = XMLString::transcode("synchro");
>
> XMLCh* chValue;
> chValue = XMLString::transcode("attValue");
>
> ((DOMElement*)pNode)->setAttribute(chName, chValue);
>
> Do I have to release the XMLCh* or this memory will be used in the DOM
tree
> in memory?
>
> XMLString::release(&chName); ???
> XMLString::release(&chValue); ???
>
> Thanks for your help.
>
> Sylvain.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: xerces-c-dev-unsubscribe@xml.apache.org
> For additional commands, e-mail: xerces-c-dev-help@xml.apache.org
>
>


---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-c-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-c-dev-help@xml.apache.org


Re: Memory question

Posted by Gareth Reakes <pa...@parthenoncomputing.com>.
Hi,
	you have to delete it.

Gareth

On Tue, 13 Apr 2004, Sylvain Duval wrote:

> Hi all,
>
> Small question about memory management :
>
> When I do a setAttribute like this on a DOMElement :
>
> XMLCh* Name;
> chName = XMLString::transcode("synchro");
>
> XMLCh* chValue;
> chValue = XMLString::transcode("attValue");
>
> ((DOMElement*)pNode)->setAttribute(chName, chValue);
>
> Do I have to release the XMLCh* or this memory will be used in the DOM tree
> in memory?
>
> XMLString::release(&chName);	???
> XMLString::release(&chValue);	???
>
> Thanks for your help.
>
> Sylvain.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: xerces-c-dev-unsubscribe@xml.apache.org
> For additional commands, e-mail: xerces-c-dev-help@xml.apache.org
>
>

-- 
Gareth Reakes, Managing Director            +44-1865-811184
Parthenon Computing                http://www.parthcomp.com




---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-c-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-c-dev-help@xml.apache.org


Memory question

Posted by Sylvain Duval <du...@jouve.fr>.
Hi all,

Small question about memory management :

When I do a setAttribute like this on a DOMElement :

XMLCh* Name;
chName = XMLString::transcode("synchro");
	
XMLCh* chValue;
chValue = XMLString::transcode("attValue");
	
((DOMElement*)pNode)->setAttribute(chName, chValue);	
	
Do I have to release the XMLCh* or this memory will be used in the DOM tree 
in memory?

XMLString::release(&chName);	???
XMLString::release(&chValue);	???

Thanks for your help.

Sylvain.


---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-c-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-c-dev-help@xml.apache.org


Re: Memory leaks and crash with MemBufInputSource

Posted by Nedelcho Stanev <ne...@lta-bg.com>.
10x for explanation :)

decho
----- Original Message -----
From: "Alberto Massari" <am...@progress.com>
To: <xe...@xml.apache.org>
Sent: Tuesday, April 13, 2004 1:46 PM
Subject: Re: Memory leaks and crash with MemBufInputSource


> Hi Nedelcho,
> your program has a very common bug: you call XMLPlatformUtils::Terminate
> before the static objects (like MemBufInputSource) have gone out of scope.
[snip]


---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-c-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-c-dev-help@xml.apache.org


Re: Memory leaks and crash with MemBufInputSource

Posted by Alberto Massari <am...@progress.com>.
Hi Nedelcho,
your program has a very common bug: you call XMLPlatformUtils::Terminate 
before the static objects (like MemBufInputSource) have gone out of scope. 
So when the destructor is invoked, it doesn't find the global state it 
relies on (the error is not that fEncoding is NULL, it's that 
fMemoryManager is pointing to deallocated memory). So you should add a { } 
block between Initialize and Terminate to be sure to delete the objects in 
the stack.

As for the memory leaks, given the presence of global state, it's better if 
you do the Checkpoint before running XMPlatformUtils::Initialize and do the 
Difference after you have called XMLPlatformUtils::Terminate

Alberto

At 13.27 13/04/2004 +0300, Nedelcho Stanev wrote:
>Hello All,
>
>I have problem using xerces 2.5.0 compiled with Visual Studio .Net on
>Windows 2000 Pro.
>I have this small source :
>
>int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
>{
>  XMLPlatformUtils::Initialize();
>  int nRetCode = 0;
>  CString mem = "<?xml version=\"1.0\" standalone=\"no\" ?><Operation
>type=\"CheckID\"></Operation>";
>#ifdef _DEBUG
>    CMemoryState oldMemState, newMemState, diffMemState;
>    oldMemState.Checkpoint();
>#endif
>  MemBufInputSource memBufIS((const XMLByte*)mem.GetBuffer(),
>mem.GetLength(), "test", false);
>  XercesDOMParser *domParser  = new XercesDOMParser;
>  domParser->parse(memBufIS);
>  delete domParser;
>  domParser = NULL;
>#ifdef _DEBUG
>    newMemState.Checkpoint();
>    if( diffMemState.Difference( oldMemState, newMemState ) )
>    {
>       TRACE( "Memory leaked!\n" );
>    diffMemState.DumpStatistics();
>    }
>#endif
>  XMLPlatformUtils::Terminate();
>  return nRetCode;
>}
>
>Using CMemoryState  in this code, i see that after deleting of parser i
>still have memory leaks:
>
> >> Memory leaked!
> >> 0 bytes in 0 Free Blocks.
> >> 660 bytes in 31 Normal Blocks.
> >> 0 bytes in 0 CRT Blocks.
> >> 0 bytes in 0 Ignore Blocks.
> >> 0 bytes in 0 Client Blocks.
> >> Largest number used: 208270 bytes.
> >> Total allocations: 208270 bytes.
>
>I try lot of ways to do this parsing from buffer, but without any success, i
>still have this leaks
>and second, when i quit from program where desctructor of MemBufInputSource
>is executed
>program crash in destructor of InputSource on this place :
>
>fMemoryManager->deallocate(fEncoding);
>
>where fEncoding is NULL.I think will be better if before to try to release
>memory some check
>will be performed , like
>
>if(fEncoding)
>     fMemoryManager->deallocate(fEncoding);
>
>about problem with memory leak i still didn't look where is the prob, so
>if someone can help i will be happy :)
>
>decho
>



---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-c-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-c-dev-help@xml.apache.org