<html>
<head>
<style>
.hmmessage P
{
margin:0px;
padding:0px
}
body.hmmessage
{
font-size: 10pt;
font-family:Verdana
}
</style>
</head>
<body class='hmmessage'>
Hi All,<BR>
<BR>When I use the C code from antlr generator with predigest PLSQL parser , I find it exist obvious memory leak issue.<BR> <BR>I use valgrind to check and the result is:<BR> <BR>valgrind --leak-check=full ./treeMemory<BR>==9541== Memcheck, a memory error detector.<BR>==9541== Copyright (C) 2002-2007, and GNU GPL'd, by Julian Seward et al.<BR>==9541== Using LibVEX rev 1854, a library for dynamic binary translation.<BR>==9541== Copyright (C) 2004-2007, and GNU GPL'd, by OpenWorks LLP.<BR>==9541== Using valgrind-3.3.1, a dynamic binary instrumentation framework.<BR>==9541== Copyright (C) 2000-2007, and GNU GPL'd, by Julian Seward et al.<BR>==9541== For more details, rerun with: -v<BR>==9541==<BR>==9541==<BR>==9541== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 17 from 1)<BR>==9541== malloc/free: in use at exit: 8,008 bytes in 98 blocks.<BR>==9541== malloc/free: 8,847 allocs, 8,749 frees, 2,202,767 bytes allocated.<BR>==9541== For counts of detected errors, rerun with: -v<BR>==9541== searching for pointers to 98 not-freed blocks.<BR>==9541== checked 149,260 bytes.<BR>==9541==<BR>==9541== 8,008 (7,560 direct, 448 indirect) bytes in 90 blocks are definitely lost in loss record 3 of 3<BR>==9541== at 0x40057C8: malloc (vg_replace_malloc.c:207)<BR>==9541== by 0x8055BFA: antlr3RewriteRuleElementStreamNewAE (antlr3rewritestreams.c:94)<BR>==9541== by 0x8055DA0: antlr3RewriteRuleTOKENStreamNewAE (antlr3rewritestreams.c:192)<BR>==9541== by 0x80B8125: select_list (PLSQLpredigestParser.c:51593)<BR>==9541== by 0x80B4E0F: select_expression (PLSQLpredigestParser.c:50283)<BR>==9541== by 0x80B3F4D: select_statement (PLSQLpredigestParser.c:49890)<BR>==9541== by 0x810C0F5: insert_command (PLSQLpredigestParser.c:83912)<BR>==9541== by 0x80B1E12: sql_command (PLSQLpredigestParser.c:49133)<BR>==9541== by 0x80B13BE: sql_statement (PLSQLpredigestParser.c:48855)<BR>==9541== by 0x8083185: statement (PLSQLpredigestParser.c:31331)<BR>==9541== by 0x808110E: seq_of_statements (PLSQLpredigestParser.c:30542)<BR>==9541== by 0x8077D5C: start_rule (PLSQLpredigestParser.c:26944)<BR>==9541==<BR>==9541== LEAK SUMMARY:<BR>==9541== definitely lost: 7,560 bytes in 90 blocks.<BR>==9541== indirectly lost: 448 bytes in 8 blocks.<BR>==9541== possibly lost: 0 bytes in 0 blocks.<BR>==9541== still reachable: 0 bytes in 0 blocks.<BR>==9541== suppressed: 0 bytes in 0 blocks.<BR>
<BR>
Source Code:<BR>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~<BR>
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' ;";<BR>
<BR> pANTLR3_INPUT_STREAM lInput=NULL;<BR> pANTLR3_COMMON_TOKEN_STREAM lPredigestTokenStream=NULL;<BR> pPLSQLpredigestParser lPredigestParser=NULL;<BR> pPLSQLpredigestLexer lPredigestLexer=NULL;<BR>
lInput = antlr3NewAsciiStringInPlaceStream((pANTLR3_UINT8)SQL.c_str(), (ANTLR3_UINT64)SQL.size(), NULL);<BR> if(!lInput)<BR> {<BR> cout<<" input error"<<endl;<BR> return -1;<BR> }<BR> lInput->setUcaseLA(lInput,ANTLR3_TRUE);<BR> <BR> lPredigestLexer = PLSQLpredigestLexerNew(lInput);<BR>
if(!lPredigestLexer)<BR> {<BR> cout<<" lPredigestLexer error"<<endl;<BR> return -1;<BR> }<BR> <BR> lPredigestTokenStream = antlr3CommonTokenStreamSourceNew(ANTLR3_SIZE_HINT, TOKENSOURCE(lPredigestLexer));<BR>
if(!lPredigestTokenStream)<BR> {<BR> cout<<" lPredigestTokenStream error"<<endl;<BR> return -1;<BR> }<BR> <BR> lPredigestParser = PLSQLpredigestParserNew(lPredigestTokenStream);<BR>
if(!lPredigestParser)<BR> {<BR> cout<<" lPredigestParser error"<<endl;<BR> return -1;<BR> <BR> }<BR> <BR><STRONG> PLSQLpredigestParser_start_rule_return psr = lPredigestParser->start_rule(lPredigestParser);<BR></STRONG> <BR> lPredigestParser->free(lPredigestParser);<BR> lPredigestTokenStream->free(lPredigestTokenStream);<BR> lPredigestLexer->free(lPredigestLexer);<BR> lInput->close(lInput);<BR>
<BR>
<BR> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~`<BR><STRONG>Actually the memory leak exist PLSQLpredigestParser_start_rule_return psr = lPredigestParser->start_rule(lPredigestParser);</STRONG><BR>
<BR>
I don't know why so simple code cause so obvious memory leak<BR><BR> <BR>Could you help me to solve this? (I'm hurry for this code, thanks a lot!)<BR> <BR>I list the information and attachment includes all code about it (C file ):<BR> <BR>Platform: RedHat Enterprise 5 Server, virtual machine.<BR>GCC version: 4.1.1<BR>Antlr Version: 3.1.1<BR> <BR><BR><BR> <BR>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 (<A href="mailto:merry_winfly@hotmail.com">merry_winfly@hotmail.com</A>).<BR> <BR><BR>Thanks a lot.<BR> <BR> <BR>Best Regards<BR>Winfly Lin<BR><BR><br /><hr />Get news, entertainment and everything you care about at Live.com. <a href='http://www.live.com/getstarted.aspx ' target='_new'>Check it out!</a></body>
</html>