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 Wyles Eric - ewyles <Er...@acxiom.com> on 2001/06/07 18:46:57 UTC

Memory Leaks (code sample included)

Hi,

I'm having a problem with memory leaks under xerces c++ 1.4.0 on Windows NT
using Visual C++ 6.0. I have two different modules using the xerces api.

1) A very small test application that I have written (code below)
2) A dll that is called by this test application, but will eventually be
called by other users (let's call this one 'myxml.dll')

Both of these are linked against the xerces libraries.

Now for my problem. My test application is attempting to build some xml,
serialize it to a string and pass it to the dll which will then parse the
string and use the data that is coming in. When I run this in debug mode
VC++ is reporting memory leaks.

I have trimmed my code down to the minimal example that will demonstrate
this behavior. Basically, if I do a LoadLibrary on my dll ('myxml.dll') AND
do a createDocument in my testapp I get the memory leaks reported. 

It is confusing because my dll that I'm loading only does xml stuff if I
make a call into an exported function (which I clearly am not). I have one
exported function that does the XMLPlatformUtils::Initialize, does some
stuff and then calls XMLPlatformUtils::Terminate. I'm not even calling this
function, just loading the dll.

I do not see the memory leaks if I either:
1) load some other dll that isn't linked against xerces ('mynonxml.dll')
or
2) leave out the createDocument but go ahead and load 'myxml.dll'

Here is the code sample that demonstrates this. Could anyone provide some
suggestions?

----------------------------------------------------------------------------
----------
#include <windows.h>
#include <stdio.h>
#include <util/PlatformUtils.hpp>
#include <util/XMLUniDefs.hpp>
#include <dom/DOM.hpp>

int main (void)
{
	HMODULE hDllHandle = NULL;
	DOM_DOMImplementation	impl;
	DOM_Document			doc;

	hDllHandle = LoadLibrary("myxml.dll"); // this one causes a leak to
be reported
//	hDllHandle = LoadLibrary("mynonxml.dll"); // this one is ok

	XMLPlatformUtils::Initialize();

	doc = impl.createDocument(
				0,
				"Input",
				DOM_DocumentType());

	XMLPlatformUtils::Terminate();

	FreeLibrary(hDllHandle);

	return 0;
}
----------------------------------------------------------------------------
---------------------

Thanks,
Eric


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