[ http://nagoya.apache.org/jira/browse/XERCESC-1228?page=history ]
     
Alberto Massari closed XERCESC-1228:
------------------------------------


> Memory leak when scanning multiple xmldocuments
> -----------------------------------------------
>
>          Key: XERCESC-1228
>          URL: http://nagoya.apache.org/jira/browse/XERCESC-1228
>      Project: Xerces-C++
>         Type: Bug
>     Versions: 2.5.0
>  Environment: Linux Mandrake 9.0
>     Reporter: Joep Simons

>
> I used valgrind (http://valgrind.kde.org/downloads.html) to track down some 
> memory leaks in my project. I could narrow the problem to this 
> piece of code:
> <SNIPPET>
> #include <xercesc/parsers/XercesDOMParser.hpp>
> #include <xercesc/dom/DOM.hpp>
> #include <xercesc/sax/HandlerBase.hpp>
> #include <xercesc/util/XMLString.hpp>
> #include <xercesc/util/PlatformUtils.hpp>
> #include <xercesc/dom/DOMDocument.hpp>
> #include <iostream>
> using namespace std;
> using namespace xercesc;
> int main(char *argv[], int argc){
>   
>   XMLPlatformUtils::Initialize();
>   XercesDOMParser *parser = new XercesDOMParser();
>   parser->setDoNamespaces(false);
>   parser->setDoSchema(true);
>   parser->setValidationSchemaFullChecking(true);      //false will be better 
> in a working system
>   parser->setValidationConstraintFatal(true);
>   parser->useCachedGrammarInParse(true);
>   parser->cacheGrammarFromParse(true);
>   XMLCh *scannerName = XMLString::transcode("SGXMLScanner");
>   parser->useScanner(scannerName);
>   XMLString::release(&scannerName);
>   try {
>       
>       parser->parse("test1.xml");
>       parser->reset();
>       // XMLCh *scannerName = XMLString::transcode("SGXMLScanner");
>       //parser->useScanner(scannerName);
>       //XMLString::release(&scannerName);
>       parser->parse("test1.xml");
>     
>   } catch (...){
>     
>     cerr << "oh dear, an exception" << endl;
>   }
>   delete parser;
>   XMLPlatformUtils::Terminate();
> }
> </SNIPPET>
> when compiled and called with valgrind, I got the folling output:
> > valgrind --leak-check=yes ./a.out
> =3058== Memcheck, a.k.a. Valgrind, a memory error detector for x86-linux.
> ==3058== Copyright (C) 2002-2003, and GNU GPL'd, by Julian Seward.
> ==3058== Using valgrind-2.0.0, a program supervision framework for x86-linux.
> ==3058== Copyright (C) 2000-2003, and GNU GPL'd, by Julian Seward.
> ==3058== Estimated CPU clock rate is 2798 MHz
> ==3058== For more details, rerun with: -v
> ==3058== 
> ==3058== pthread_mutex_destroy: mutex is still in use
> ==3058==    at 0x40792D4E: pthread_error (vg_libpthread.c:288)
> ==3058==    by 0x406D8F0B: _IO_default_finish (in /lib/i686/libc-2.2.5.so)
> ==3058==    by 0x406D742C: _IO_file_finish (in /lib/i686/libc-2.2.5.so)
> ==3058==    by 0x406CBCAA: _IO_fclose (in /lib/i686/libc-2.2.5.so)
> ==3058== 
> ==3058== pthread_mutex_unlock: mutex is not locked
> ==3058==    at 0x40793BFF: __pthread_mutex_unlock (vg_libpthread.c:993)
> ==3058==    by 0x406CBD3E: _IO_fclose (in /lib/i686/libc-2.2.5.so)
> ==3058==    by 0x4042F384: xercesc_2_5::XMLPlatformUtils::closeFile(void*, 
> xercesc_2_5::MemoryManager*) (LinuxPlatformUtils.cpp:365)
> ==3058==    by 0x403716E5: 
> xercesc_2_5::BinFileInputStream::~BinFileInputStream() 
> (BinFileInputStream.cpp:144)
> ==3058== 
> ==3058== ERROR SUMMARY: 4 errors from 2 contexts (suppressed: 0 from 0)
> ==3058== malloc/free: in use at exit: 12 bytes in 1 blocks.
> ==3058== malloc/free: 1000 allocs, 999 frees, 419102 bytes allocated.
> ==3058== For counts of detected errors, rerun with: -v
> ==3058== searching for pointers to 1 not-freed blocks.
> ==3058== checked 9002408 bytes.
> ==3058== 
> ==3058== 
> ==3058== 12 bytes in 1 blocks are definitely lost in loss record 1 of 1
> ==3058==    at 0x400261BC: __builtin_new (vg_replace_malloc.c:172)
> ==3058==    by 0x40026214: operator new(unsigned) (vg_replace_malloc.c:185)
> ==3058==    by 0x40434DFE: xercesc_2_5::MemoryManagerImpl::allocate(unsigned) 
> (MemoryManagerImpl.cpp:83)
> ==3058==    by 0x40360ADD: xercesc_2_5::XMLString::replicate(unsigned short 
> const*, xercesc_2_5::MemoryManager*) 
> (/usr/local/xerces-c-src_2_5_0/include/xercesc/util/XMLString.hpp:1599)
> ==3058== 
> ==3058== LEAK SUMMARY:
> ==3058==    definitely lost: 12 bytes in 1 blocks.
> ==3058==    possibly lost:   0 bytes in 0 blocks.
> ==3058==    still reachable: 0 bytes in 0 blocks.
> ==3058==         suppressed: 0 bytes in 0 blocks.
> ==3058== Reachable blocks (those to which a pointer was found) are not shown.
> ==3058== To see them, rerun with: --show-reachable=yes
> ==3058== 
> When I uncommented the part in the snippet which is now commented out it does 
> not give any memory errors.
> For this run I used the following xml document although I found the same 
> problem using others:
> <?xml version="1.0"?>
> <batch>
>       <evref>file://localhost/test2.xml</evref>
> </batch>
> best regards,
>   Joep

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://nagoya.apache.org/jira/secure/Administrators.jspa
-
If you want more information on JIRA, or have a bug to report see:
   http://www.atlassian.com/software/jira


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to