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 Farkas Lajos <la...@integrasoft.ro> on 2000/12/20 13:49:32 UTC

Memory leak?!

Hi all!
I use the folowing sequence of code to parse an xml file (from memory).
Each time when i parse a file, i got an exception if i try to delete the
memBufIS object. If i don't delete it, then i got a memory leak. If i parse
a file, there is no leak. I'm doing something wrong?!

     parser=new DOMParser();
     docHandler = new HandlerBase();
     ErrorHandler* errHandler = (ErrorHandler*) docHandler;

     parser->setErrorHandler(errHandler);

     unsigned short buffid;
     XMLByte *b=new XMLByte[s->length()];
/* fill the b with the xml file */

     MemBufInputSource *memBufIS=new MemBufInputSource( b, s->length(),
&buffid, true );
       try
        {
              parser->parse( *memBufIS );
          }
    catch (const XMLException& e)
    {
      printf("Error parsing XML document,%d\n",e.getCode() );
     }

/* code here*/
 delete parser;
 delete docHandler;
 delete []b;
/* Exception at this delete */
delete memBufIS;

Kind Regards,
LAji


Re: Memory leak?!

Posted by Farkas Lajos <la...@integrasoft.ro>.
10x Bill, it's working...

LAji
----- Original Message -----
From: "Bill Schindler" <de...@bitranch.com>
To: <xe...@xml.apache.org>
Sent: Wednesday, December 20, 2000 5:27 PM
Subject: Re: Memory leak?!


> "Farkas Lajos" <la...@integrasoft.ro> wrote:
> > MemBufInputSource *memBufIS=new MemBufInputSource( b, s->length(),
> > &buffid, true );
> > [[ ... ]]
> > delete []b;
> > /* Exception at this delete */
> > delete memBufIS;
>
> You've told MemBufInputSource to adopt the buffer you're passing in (your
> "b"), and then deleting the buffer yourself. Since you told
> MemBufInputSource to adopt the buffer, it then tries to delete the buffer
in
> its destructor. That's probably the cause of your exception.
>
> You need to either remove the "delete [] b" or change the
MemBufInputSource
> constructor's last parameter to false.
>
>
> --Bill
>
>
> ---------------------------------------------------------------------
> 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 leak?!

Posted by Bill Schindler <de...@bitranch.com>.
"Farkas Lajos" <la...@integrasoft.ro> wrote:
> MemBufInputSource *memBufIS=new MemBufInputSource( b, s->length(),
> &buffid, true );
> [[ ... ]]
> delete []b;
> /* Exception at this delete */
> delete memBufIS;

You've told MemBufInputSource to adopt the buffer you're passing in (your
"b"), and then deleting the buffer yourself. Since you told
MemBufInputSource to adopt the buffer, it then tries to delete the buffer in
its destructor. That's probably the cause of your exception.

You need to either remove the "delete [] b" or change the MemBufInputSource
constructor's last parameter to false.


--Bill