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 "Foong, Tzeweng" <Tz...@team.telstra.com> on 2000/12/06 07:09:33 UTC
Why does "delete [] p" keep failing?
Hello all,
I have just joined this list !! The first time I saw xerces was a few days
ago!
I have been reading the archives and the docs but I cannot find a solution
to
something thats really annoying.
Its probably not the fault of xerces but I still need help in resolving
this.
I am using Visual C++. ( I will be porting the code to solaris after I get
it going on windows)
I copied the code below from the DOMPrint sample.
----------------------------------------
ostream& operator<< (ostream& target, const DOMString& s)
{
char *p = s.transcode();
target << p;
delete [] p;
return target;
}
---------------------------------------
The "delete [] p;" statement throws up the following error.
----------------------------------------------------------------------------
---
Microsoft Visual C++ Debug Library
Debug Assertion Failed!
Program: ................\MyProg\Debug\MyProg.exe
File: dbgheap.c
Line : 1011
Expression: _CrtlsValidHeapPointer(pUserData)
For information on how your program can cause an assertion
failure, see the Visual C++ documentation on asserts.
(Press Retry to debug the application)
[ Abort ] [ Retry ] [ Ignore ]
----------------------------------------------------------------------------
My own function as below does the same thing.
----------------------------------------------
void dbgNode(DOM_Node *n)
{
DOMString s;
char *pn;
char *pv;
if (! n->isNull())
{
s = n->getNodeName();
pn = s.transcode();
delete [] pn;
s = n->getNodeValue();
pv = s.transcode();
delete [] pv;
}
}
-----------------------------------------------
However !! The "ostream& operator<< ()" run from within the DOMPrint
example does not give an error.!! Why is this ???
The following is a serialser type function I wrote which causes the
"ostream& operator<< ()" to throw up the error. Note I have done a basic
hack of the Code from the DOMPrint example. You can still see the
original code commented out.
----------------------------------------------------------------------------
--
// Stream out a DOM node, and, recursively, all of its children. To the
file
// specified.
int writeDom(char *filename, DOM_Node& toWrite)
{
int retval;
ofstream outf;
retval = false;
outf.open(filename);
if (outf.fail())
return retval;
else
{
// DOM_Node doc = parser->getDocument();
DOMPrintFormatTarget* formatTarget = new DOMPrintFormatTarget();
if (gEncodingName == 0)
{
DOMString encNameStr("UTF-8");
// DOM_Node aNode = doc.getFirstChild();
// if (aNode.getNodeType() == DOM_Node::XML_DECL_NODE)
if (toWrite.getNodeType() == DOM_Node::XML_DECL_NODE)
{
// DOMString aStr = ((DOM_XMLDecl &)aNode).getEncoding();
DOMString aStr = ((DOM_XMLDecl &)toWrite).getEncoding();
if (aStr != "")
{
encNameStr = aStr;
}
}
unsigned int lent = encNameStr.length();
gEncodingName = new XMLCh[lent + 1];
XMLString::copyNString(gEncodingName, encNameStr.rawBuffer(),
lent);
gEncodingName[lent] = 0;
}
try
{
gFormatter = new XMLFormatter(gEncodingName, formatTarget,
XMLFormatter::NoEscapes,
gUnRepFlags);
// cout << doc << endl;
///////// This is the place it fails !!!!!!!!!!!!!
outf << toWrite << endl;
retval = true;
}
catch (XMLException& e)
{
cerr << "An error occurred during creation of output transcoder.
Msg is:"
<< endl
<< DOMString(e.getMessage()) << endl;
retval = 3;
}
delete formatTarget;
delete gFormatter;
return retval;
}
}
----------------------------------------------------------------------------
--------------
Hope someone can help. otherwise My program is going to leak like a seive
if i comment out the "delete [] p;" statement. But I am going to have to do
that to get it to work !
Thanks in advance...
Tze Weng Foong
Re: Why does "delete [] p" keep failing?
Posted by Dean Roddey <dr...@charmedquark.com>.
You are using debug and relese runtimes simultaneously. The parser releases
are 'release' builds. You are bulding your program as a debug build, which
means that they are using different runtimes. If you use the release builds,
then you must build your program with the "Multi-threaded DLL" runtime. I
think that the most recent release might come with a 'd' version of the DLL,
which is built for debug in which case you build your program with
"Multi-threaded Debug DLL".
--------------------------
Dean Roddey
The CIDLib C++ Frameworks
Charmed Quark Software
droddey@charmedquark.com
http://www.charmedquark.com
"It takes two buttocks to make friction"
- African Proverb
----- Original Message -----
From: "Foong, Tzeweng" <Tz...@team.telstra.com>
To: <xe...@xml.apache.org>
Sent: Tuesday, December 05, 2000 10:09 PM
Subject: Why does "delete [] p" keep failing?
> Hello all,
>
> I have just joined this list !! The first time I saw xerces was a few days
> ago!
>
> I have been reading the archives and the docs but I cannot find a solution
> to
> something thats really annoying.
>
> Its probably not the fault of xerces but I still need help in resolving
> this.
> I am using Visual C++. ( I will be porting the code to solaris after I
get
> it going on windows)
>
>
> I copied the code below from the DOMPrint sample.
> ----------------------------------------
> ostream& operator<< (ostream& target, const DOMString& s)
> {
> char *p = s.transcode();
> target << p;
> delete [] p;
> return target;
> }
> ---------------------------------------
>
> The "delete [] p;" statement throws up the following error.
>
> --------------------------------------------------------------------------
--
> ---
> Microsoft Visual C++ Debug Library
>
> Debug Assertion Failed!
> Program: ................\MyProg\Debug\MyProg.exe
> File: dbgheap.c
> Line : 1011
>
> Expression: _CrtlsValidHeapPointer(pUserData)
>
> For information on how your program can cause an assertion
> failure, see the Visual C++ documentation on asserts.
>
> (Press Retry to debug the application)
> [ Abort ] [ Retry ] [ Ignore ]
> --------------------------------------------------------------------------
--
>
>
> My own function as below does the same thing.
> ----------------------------------------------
> void dbgNode(DOM_Node *n)
> {
> DOMString s;
> char *pn;
> char *pv;
>
> if (! n->isNull())
> {
> s = n->getNodeName();
> pn = s.transcode();
> delete [] pn;
> s = n->getNodeValue();
> pv = s.transcode();
> delete [] pv;
> }
> }
> -----------------------------------------------
>
> However !! The "ostream& operator<< ()" run from within the DOMPrint
> example does not give an error.!! Why is this ???
>
> The following is a serialser type function I wrote which causes the
> "ostream& operator<< ()" to throw up the error. Note I have done a basic
> hack of the Code from the DOMPrint example. You can still see the
> original code commented out.
> --------------------------------------------------------------------------
--
> --
> // Stream out a DOM node, and, recursively, all of its children. To the
> file
> // specified.
> int writeDom(char *filename, DOM_Node& toWrite)
> {
> int retval;
> ofstream outf;
>
> retval = false;
> outf.open(filename);
> if (outf.fail())
> return retval;
> else
> {
>
> // DOM_Node doc = parser->getDocument();
> DOMPrintFormatTarget* formatTarget = new DOMPrintFormatTarget();
>
> if (gEncodingName == 0)
> {
> DOMString encNameStr("UTF-8");
> // DOM_Node aNode = doc.getFirstChild();
> // if (aNode.getNodeType() == DOM_Node::XML_DECL_NODE)
> if (toWrite.getNodeType() == DOM_Node::XML_DECL_NODE)
> {
> // DOMString aStr = ((DOM_XMLDecl &)aNode).getEncoding();
> DOMString aStr = ((DOM_XMLDecl &)toWrite).getEncoding();
> if (aStr != "")
> {
> encNameStr = aStr;
> }
> }
> unsigned int lent = encNameStr.length();
> gEncodingName = new XMLCh[lent + 1];
> XMLString::copyNString(gEncodingName, encNameStr.rawBuffer(),
> lent);
> gEncodingName[lent] = 0;
> }
>
>
> try
> {
> gFormatter = new XMLFormatter(gEncodingName, formatTarget,
> XMLFormatter::NoEscapes,
> gUnRepFlags);
>
> // cout << doc << endl;
> ///////// This is the place it fails !!!!!!!!!!!!!
> outf << toWrite << endl;
> retval = true;
>
> }
> catch (XMLException& e)
> {
> cerr << "An error occurred during creation of output
transcoder.
> Msg is:"
> << endl
> << DOMString(e.getMessage()) << endl;
> retval = 3;
> }
>
> delete formatTarget;
> delete gFormatter;
>
> return retval;
> }
> }
> --------------------------------------------------------------------------
--
> --------------
> Hope someone can help. otherwise My program is going to leak like a seive
> if i comment out the "delete [] p;" statement. But I am going to have to
do
> that to get it to work !
>
> Thanks in advance...
>
> Tze Weng Foong
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: xerces-c-dev-unsubscribe@xml.apache.org
> For additional commands, e-mail: xerces-c-dev-help@xml.apache.org
>