bugSimple C Expat Wrapper - Bugs: bug #17976, memory leak reported by valgrind...

 
 

bug #17976: memory leak reported by valgrind after scew_parser_load_buffer

Submitted by:  None
Submitted on:  Wed 11 Oct 2006 05:17:35 PM UTC  
 
Category: NoneSeverity: 3 - Normal
Item Group: NoneStatus: Fixed
Privacy: PublicAssigned to: Aleix Conchillo Flaqué <aleix>
Open/Closed: Closed

Add a New Comment(Rich Markup)
   

You are not logged in

Please log in, so followups can be emailed to you.

 

(Jump to the original submission Jump to the original submission)

Mon 24 Aug 2009 10:47:56 PM UTC, comment #7:

Documentation fixed, will be available in SCEW 1.0.

Thanks.

Aleix Conchillo Flaqué <aleix>
Project AdministratorIn charge of this item.
Mon 18 Jun 2007 10:08:02 AM UTC, comment #6:

There seems to be an inconsistency in TFM actually...

from tree.h :
/**

  • Frees a tree memory structure. Call this function when you are done
  • with your XML. Do not call this function with a
  • <code>scew_tree</code> obtained via a <code>scew_parser</code>,
  • because <code>scew_parser</code> will delete it automatically when
  • freed.

*/
extern void
scew_tree_free(scew_tree* tree);

That seems to be in contradiction with scew_parser documentation, and is just plain wrong.

Eric

Anonymous
Fri 13 Oct 2006 06:12:20 PM UTC, comment #5:

Thanks - another RTFM :-)

Anonymous
Wed 11 Oct 2006 11:35:07 PM UTC, comment #4:

The documentation of scew_parser_create says:

Frees a parser memory structure. This function will not free the scew_tree generated by the parser, so it is important that you keep a pointer to it and remember to free it.

So, you need to free the tree your self in your code.

Aleix Conchillo Flaqué <aleix>
Project AdministratorIn charge of this item.
Wed 11 Oct 2006 08:16:32 PM UTC, comment #3:

If i change scew_parser_free to the following the leak is gone. Is that an ok change to make do you think??

void
scew_parser_free(scew_parser* parser)
{
if (parser != NULL)
{
if (parser->tree)
{
scew_tree_free(parser->tree);
}
if (parser->parser)
{
XML_ParserFree(parser->parser);
}
free(parser);
}
}

Anonymous
Wed 11 Oct 2006 06:12:40 PM UTC, comment #2:

i have posted this same info on the expat site - cause i think it is actually an expat leak.

Anonymous
Wed 11 Oct 2006 05:20:07 PM UTC, comment #1:

should have mentioned - i am using the latest scew (0.4.0?) on redhat linux (x86).

Anonymous
Wed 11 Oct 2006 05:17:35 PM UTC, original submission:

Hi -

I ran a very simple test through valgrind and have a possible memory leak. Here's the code

#include <iostream>
#include <string>
#include "scew.h"

int main(int argc, char *argv[])
{
char * data = {"<X />"};
scew_parser* parser = scew_parser_create();
if (!parser) {
return -1;
}
scew_parser_ignore_whitespaces(parser, 1);

if (scew_parser_load_buffer(parser, data, strlen(data))){
std::cout << "OK\n";
}
else {
std::cout << "Bad\n";
}

scew_parser_free(parser);
}

and here's the valgrind output. I don't think i am doing anything wrong - but there's always that chance :-)

==9103== 70 (20 direct, 50 indirect) bytes in 1 blocks are definitely lost in loss record 3 of 5
==9103== at 0x4018B0F: calloc (m_replacemalloc/vg_replace_malloc.c:279)
==9103== by 0x80499A7: scew_tree_create (in /home/tracy/test/x)
==9103== by 0x80490B4: start_handler (in /home/tracy/test/x)
==9103== by 0x40E3D50: doContent (in /usr/lib/libexpat.so.0.3.0)
==9103== by 0x40E33C7: contentProcessor (in /usr/lib/libexpat.so.0.3.0)
==9103== by 0x40E5FC1: doProlog (in /usr/lib/libexpat.so.0.3.0)
==9103== by 0x40E5D80: prologProcessor (in /usr/lib/libexpat.so.0.3.0)
==9103== by 0x40E2F4B: XML_ParseBuffer (in /usr/lib/libexpat.so.0.3.0)
==9103== by 0x40E2EDA: XML_Parse (in /usr/lib/libexpat.so.0.3.0)
==9103== by 0x8048F58: scew_parser_load_buffer (in /home/tracy/test/x)
==9103== by 0x8048C3A: main (x.cpp:15)
==9103==
==9103== LEAK SUMMARY:
==9103== definitely lost: 20 bytes in 1 blocks.
==9103== indirectly lost: 50 bytes in 3 blocks.
==9103== possibly lost: 0 bytes in 0 blocks.
==9103== still reachable: 116 bytes in 1 blocks.
==9103== suppressed: 0 bytes in 0 blocks.

Anonymous

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach File(s):
   
   
Comment:
   

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -unavailable- added by aleix (Updated the item)
  •  

    Do you think this task is very important?
    If so, you can click here to add your encouragement to it.
    This task has 0 encouragements so far.

    Only logged-in users can vote.

     

    Please enter the title of George Orwell's famous dystopian book (it's a date):

     

     

    Follow 4 latest changes.

    Date Changed By Updated Field Previous Value => Replaced By
    Tue 01 Sep 2009 12:04:46 AM UTCaleixOpen/ClosedOpen=>Closed
    Mon 24 Aug 2009 10:47:56 PM UTCaleixStatusInvalid=>Fixed
    Mon 18 Jun 2007 10:29:38 AM UTCaleixAssigned toNone=>aleix
    Wed 11 Oct 2006 11:35:07 PM UTCaleixStatusNone=>Invalid

    Back to the top


    Powered by Savane 3.1-cleanup1