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 Yakov Becker <ya...@btech.co.il> on 2001/06/15 15:59:44 UTC
RE: Correct Way to dispose of strings from XMLString::transcode - Problems with BCB
Ray,
I have the same problems with Borland C++ 5.0
I have memory leak in
char *attrValC = node.getNodeName().transcode();
AnsiString NodeName = attrValC;
delete[] attrValC;
When I run it with CodeGuard (BCB debugging program) it get message
"Bad object array" on delete[] attrValC;
I checked the Xerces Dll and my project settings. They are the same.
Anybody can help?
Yakov
-----Original Message-----
From: Bruce Bailey [mailto:bjb@plaza.ds.adp.com]
Sent: Thursday, June 14, 2001 18:19
To: 'xerces-c-dev@xml.apache.org'
Subject: RE: Correct Way to dispose of strings from XMLString::transcode
Ray
Thanks so much for the information. I ran a simple test with a one-function
DLL and verified that this is indeed the problem.
I must be missing something however. This seems like a problem that most
Win programmers are going to run into. Why aren't the standard distribution
packages for windows using static libraries rather than DLL's?
Thanks,
Bruce
> -----Original Message-----
> From: Mitchell, Raymond [mailto:Raymond_Mitchell@intuit.com]
> Sent: Wednesday, June 13, 2001 3:54 PM
> To: 'xerces-c-dev@xml.apache.org'
> Subject: RE: Correct Way to dispose of strings from
> XMLString::transcode
>
>
> When linking to Xerces-C, you must make sure you are linking
> with the same
> runtime library that the Xerces-C DLL links with. The
> Xerces-C DLL links to
> the multithreaded DLL version of the runtime library by
> default. To use the
> Xerces-C DLL as it ships, your program must link to the
> multithreaded DLL
> version of the runtime library as well.
>
> Visual C++ provides three versions of the runtime libraries:
> multithreaded
> DLL, multithreaded static, singlethreaded static. If your
> program cannot be
> linked to the multithreaded DLL runtime library, then it must
> be linking to
> one of the two static libraries. You cannot simply rebuild
> the Xerces-C DLL
> to link with the same static library as your program. This
> is because DLL's
> are seperately linkable units (the same as executables).
> Even though both
> your program and Xerces-C would be linking to the same static runtime
> library, each would maintain its own heap. It would be
> illegal for the
> memory returned by Xerces-C to be deleted by your program.
>
> The way around this is to recompile Xerces-C as a statically
> linked library
> (create a new project of type "Static Library" in Visual
> C++). Link your
> program to the static library version of Xerces-C and
> everything should work
> fine. The static library version of Xerces-C will now
> actually be part of
> your program and hence share the same heap with it.
>
> I hope this helps,
> Ray
>
> -----Original Message-----
> From: Bruce Bailey [mailto:bjb@plaza.ds.adp.com]
> Sent: Wednesday, June 13, 2001 2:25 PM
> To: 'Xerces List'
> Subject: Correct Way to dispose of strings from XMLString::transcode
>
>
> Hi
>
> When trying to run the following program, I keep getting an
> invalid heap
> pointer error. This occurs whenever I try to delete either
> the XML string
> or the normal string. If I don't use 'delete', I get memory
> leaks. Any
> ideas as to what might be the problem?
>
> Thanks.
>
> Bruce
>
> Platform: Winnt 4.0 (not sure of sp level, but I think it's 5)
> Compiler: vc 6.0
> Xerces version: VER=1_4
>
> #include <util\XMLString.hpp>
> #include <util/PlatformUtils.hpp>
>
> int
> main(int argc, char *argv[])
> {
> XMLPlatformUtils::Initialize();
>
> XMLCh *x = XMLString::transcode("This is a test");
> char *p = XMLString::transcode(x);
>
> delete x; /* delete[] x doesn't work either*/
> delete[]p;
>
> XMLPlatformUtils::Terminate();
>
> return 0;
> }
>
> ---------------------------------------------------------------------
> 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
>
---------------------------------------------------------------------
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