From: thierry <thi...@di...> - 2003-04-23 15:58:11
|
I have encountered a memory leak (not signalized by Purify) in the class = SaxParser. in the function parse() : "_context->sax =3D & _sax_handler; [..] release_underlying();" is not valid. structure allocated in xmlCreateMemoryParserCtxt for the = sax handler is never released due to=20 "_context->sax =3D 0 " in release_underlying(). The solution I have found was to use memcpy and to really release sax = object of context. I don't how to make patch so this is how looks my corrections in parse void SaxParser::parse(){ if(!_context) throw internal_error("Parse context not created."); //_context->sax =3D & _sax_handler; memcpy(_context->sax, &_sax_handler, sizeof(xmlSAXHandler)); _context->userData =3D this; initialize_context(); xmlParseDocument(_context); if( (! _context->wellFormed) && (! _exception) ) _exception =3D new parse_error("Document not well-formed"); //release_underlying(); xmlFreeParserCtxt(_context); _context =3D 0; check_for_exception(); } best regards Thierry Blanchard |
From: Christophe de V. <cde...@al...> - 2003-04-23 17:03:46
|
=2D----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Le Mercredi 23 Avril 2003 18:04, thierry a =E9crit : > I have encountered a memory leak (not signalized by Purify) in the class > SaxParser. in the function parse() : > > "_context->sax =3D & _sax_handler; > > [..] > > release_underlying();" > > is not valid. structure allocated in xmlCreateMemoryParserCtxt for the sax > handler is never released due to > > "_context->sax =3D 0 " in release_underlying(). > Thanks for reporting this problem. In fact the good solution is probably to use xmlSAXUserParseFile and=20 xmlSAXUserParseMemory to create the contexts, and not=20 xmlCreateMemoryParserCtxt and xmlCreateFileParserCtxt which are to be used= =20 only for DOM. I'll commit a patch by the evening. Best regards, Christophe =2D----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.1 (GNU/Linux) iD8DBQE+psdLB+sU3TyOQjARAkp2AJ9gnVSX/K/WP8R/SVH2y7YHRot7fwCgt5rY 7oTxeM09/oC9XgOpsHrTt00=3D =3Dko17 =2D----END PGP SIGNATURE----- |
From: Christophe de V. <cde...@al...> - 2003-04-23 23:15:13
|
Le Mercredi 23 Avril 2003 19:03, Christophe de VIENNE a =E9crit : > In fact the good solution is probably to use xmlSAXUserParseFile and > xmlSAXUserParseMemory to create the contexts, and not > xmlCreateMemoryParserCtxt and xmlCreateFileParserCtxt which are to be used > only for DOM. It seems I've spoken a bit fast sorry ;-) We can't do that. The functions I= =20 spoke about don't return a context. So we have to make sure either the sax handler can be freed by libxml, eith= er=20 handle it ourselves. The proposed solution was not handling the same problem happening with=20 xmlCreatePushParserCtxt, that we use for parse_chunk and parse_stream, whic= h=20 makes a copy of the sax handle we give to it, and this copy is never=20 released. So I removed the reset of sax handler in release_underlying. In parse, I ju= st=20 save the defaut sax parser and restore after parsing, as it is done in=20 xmlCreateMemoryParserCtxt for example. I think this correct the problem(s). Cheers, Christophe |
From: thierry <thi...@di...> - 2003-04-24 07:50:18
|
at it is done in xmlSAXUserParseMemory... I think this is the best solution. Thank you for your immediate reaction. Good luck Thierry ----- Original Message ----- From: "Christophe de Vienne" <cde...@al...> To: <lib...@li...> Sent: Thursday, April 24, 2003 1:13 AM Subject: Re: [libxml++] memory leak in SaxParser Le Mercredi 23 Avril 2003 19:03, Christophe de VIENNE a écrit : > In fact the good solution is probably to use xmlSAXUserParseFile and > xmlSAXUserParseMemory to create the contexts, and not > xmlCreateMemoryParserCtxt and xmlCreateFileParserCtxt which are to be used > only for DOM. It seems I've spoken a bit fast sorry ;-) We can't do that. The functions I spoke about don't return a context. So we have to make sure either the sax handler can be freed by libxml, either handle it ourselves. The proposed solution was not handling the same problem happening with xmlCreatePushParserCtxt, that we use for parse_chunk and parse_stream, which makes a copy of the sax handle we give to it, and this copy is never released. So I removed the reset of sax handler in release_underlying. In parse, I just save the defaut sax parser and restore after parsing, as it is done in xmlCreateMemoryParserCtxt for example. I think this correct the problem(s). Cheers, Christophe ------------------------------------------------------- This sf.net email is sponsored by:ThinkGeek Welcome to geek heaven. http://thinkgeek.com/sf _______________________________________________ Libxmlplusplus-general mailing list Lib...@li... https://lists.sourceforge.net/lists/listinfo/libxmlplusplus-general |
From: Christophe de V. <cde...@al...> - 2003-04-24 13:54:29
|
=2D----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Le Jeudi 24 Avril 2003 09:56, thierry a =E9crit : > as it is done in xmlSAXUserParseMemory... yes. =2D----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.1 (GNU/Linux) iD8DBQE+p+yPB+sU3TyOQjARAkMfAJ0VOs0IOGcUSrm/ttAftq6TDPtLGwCdFBuI iR6XX4Wa+zd+uYDT0HkeAp8=3D =3DV31n =2D----END PGP SIGNATURE----- |