[antlr-interest] Antlr C code memory leak in Antlr 3.1.1

merry_winfly at hotmail.com merry_winfly at hotmail.com
Mon Nov 10 05:21:04 PST 2008


Hi All,
 When I use the C code from antlr generator with predigest PLSQL parser  , I find it exist obvious memory leak issue. I use valgrind  to check and the result is: valgrind --leak-check=full ./treeMemory==9541== Memcheck, a memory error detector.==9541== Copyright (C) 2002-2007, and GNU GPL'd, by Julian Seward et al.==9541== Using LibVEX rev 1854, a library for dynamic binary translation.==9541== Copyright (C) 2004-2007, and GNU GPL'd, by OpenWorks LLP.==9541== Using valgrind-3.3.1, a dynamic binary instrumentation framework.==9541== Copyright (C) 2000-2007, and GNU GPL'd, by Julian Seward et al.==9541== For more details, rerun with: -v==9541====9541====9541== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 17 from 1)==9541== malloc/free: in use at exit: 8,008 bytes in 98 blocks.==9541== malloc/free: 8,847 allocs, 8,749 frees, 2,202,767 bytes allocated.==9541== For counts of detected errors, rerun with: -v==9541== searching for pointers to 98 not-freed blocks.==9541== checked 149,260 bytes.==9541====9541== 8,008 (7,560 direct, 448 indirect) bytes in 90 blocks are definitely lost in loss record 3 of 3==9541==    at 0x40057C8: malloc (vg_replace_malloc.c:207)==9541==    by 0x8055BFA: antlr3RewriteRuleElementStreamNewAE (antlr3rewritestreams.c:94)==9541==    by 0x8055DA0: antlr3RewriteRuleTOKENStreamNewAE (antlr3rewritestreams.c:192)==9541==    by 0x80B8125: select_list (PLSQLpredigestParser.c:51593)==9541==    by 0x80B4E0F: select_expression (PLSQLpredigestParser.c:50283)==9541==    by 0x80B3F4D: select_statement (PLSQLpredigestParser.c:49890)==9541==    by 0x810C0F5: insert_command (PLSQLpredigestParser.c:83912)==9541==    by 0x80B1E12: sql_command (PLSQLpredigestParser.c:49133)==9541==    by 0x80B13BE: sql_statement (PLSQLpredigestParser.c:48855)==9541==    by 0x8083185: statement (PLSQLpredigestParser.c:31331)==9541==    by 0x808110E: seq_of_statements (PLSQLpredigestParser.c:30542)==9541==    by 0x8077D5C: start_rule (PLSQLpredigestParser.c:26944)==9541====9541== LEAK SUMMARY:==9541==    definitely lost: 7,560 bytes in 90 blocks.==9541==    indirectly lost: 448 bytes in 8 blocks.==9541==      possibly lost: 0 bytes in 0 blocks.==9541==    still reachable: 0 bytes in 0 blocks.==9541==         suppressed: 0 bytes in 0 blocks.
 
Source Code:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
string SQL="insert into T K(a1,a2,a3) select a,b,c from t2 where a>9 union all select e,f,g from t5 where e>'winfly' ;";
    pANTLR3_INPUT_STREAM lInput=NULL; pANTLR3_COMMON_TOKEN_STREAM lPredigestTokenStream=NULL; pPLSQLpredigestParser lPredigestParser=NULL; pPLSQLpredigestLexer lPredigestLexer=NULL;
 lInput = antlr3NewAsciiStringInPlaceStream((pANTLR3_UINT8)SQL.c_str(), (ANTLR3_UINT64)SQL.size(), NULL); if(!lInput) {  cout<<" input error"<<endl;  return -1; } lInput->setUcaseLA(lInput,ANTLR3_TRUE);     lPredigestLexer = PLSQLpredigestLexerNew(lInput);
 if(!lPredigestLexer) {  cout<<" lPredigestLexer error"<<endl;  return -1; }     lPredigestTokenStream = antlr3CommonTokenStreamSourceNew(ANTLR3_SIZE_HINT, TOKENSOURCE(lPredigestLexer));
 if(!lPredigestTokenStream) {  cout<<" lPredigestTokenStream error"<<endl;  return -1; }     lPredigestParser = PLSQLpredigestParserNew(lPredigestTokenStream);
 if(!lPredigestParser) {  cout<<" lPredigestParser error"<<endl;  return -1;         }     PLSQLpredigestParser_start_rule_return psr = lPredigestParser->start_rule(lPredigestParser);   lPredigestParser->free(lPredigestParser); lPredigestTokenStream->free(lPredigestTokenStream); lPredigestLexer->free(lPredigestLexer); lInput->close(lInput);
 
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~`Actually the memory leak exist PLSQLpredigestParser_start_rule_return psr = lPredigestParser->start_rule(lPredigestParser);
 
I don't know why so simple code cause so obvious memory leak Could you help me to solve this? (I'm hurry for this code, thanks a lot!) I list the information and attachment includes all code about it (C file ): Platform: RedHat Enterprise 5 Server, virtual machine.GCC version: 4.1.1Antlr Version: 3.1.1  I don't know if it is enough information to trace this problem, but if you want to know any more information, pls freely contact me with this E-mail (merry_winfly at hotmail.com). Thanks a lot.  Best RegardsWinfly Lin
_________________________________________________________________
News, entertainment and everything you care about at Live.com. Get it now!
http://www.live.com/getstarted.aspx
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20081110/cba75556/attachment.html 


More information about the antlr-interest mailing list