Memory Leaks under VC++ 6 when using TokenStreamHiddenTokenFilter
0 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Tim_Stewart
Posted On:   Wednesday, February 6, 2002 02:42 PM

Here is my grammar file (Simple.g): options { language="Cpp"; namespaceAntlr="antlr"; } class SimpleParser extends Parser; startRule : ( WORD )* ; class SimpleLexer extends Lexer; WORD : ( 'a'..'z' | 'A'..'Z' )+ ; WS : ( ' ' | ' ' | ' ' )+ ; COMMENT : '*' (~('$'))? // If I change the ? to a + there are no leaks ; It's as small as I could get it and still reproduce the leaks. Here is my main.cpp file (the file that drives the parser): #include    More>>

Here is my grammar file (Simple.g):

			
options
{
language="Cpp";
namespaceAntlr="antlr";
}

class SimpleParser extends Parser;

startRule
: ( WORD )*
;

class SimpleLexer extends Lexer;

WORD
: ( 'a'..'z' | 'A'..'Z' )+
;

WS
: ( ' ' | '
' | '
' )+
;


COMMENT
: '*' (~('$'))? // If I change the ? to a + there are no leaks
;


It's as small as I could get it and still reproduce the leaks.


Here is my main.cpp file (the file that drives the parser):



			
#include
#include
#include "antlr/CommonHiddenStreamToken.hpp"
#include "antlr/TokenStreamHiddenTokenFilter.hpp"
#include "SimpleLexer.hpp"
#include "SimpleParser.hpp"

using namespace antlr;
using namespace std;

int main( )
{
// So that a leak report is generated (in the event of leaks)
_CrtSetDbgFlag( _CRTDBG_LEAK_CHECK_DF | _CRTDBG_ALLOC_MEM_DF );

ifstream in( "SimpleInput", ios_base::in | ios_base::binary );

SimpleLexer lexer( in );
lexer.setTokenObjectFactory(&antlr::CommonHiddenStreamToken::factory);

// If I don't use a TokenStreamHiddenTokenFilter, there are no leaks
TokenStreamHiddenTokenFilter filter(lexer);
filter.hide(SimpleLexer.WS);
filter.hide(SimpleLexer.COMMENT);

SimpleParser parser( filter );

parser.startRule();

return 0;
}



My input file is:



			
*f




that
is a real new line not '\' and 'n'.


When I run this program in debug mode, I get the following leak report:



			
Detected memory leaks!
Dumping objects ->
{206} normal block at 0x002F8FB0, 8 bytes long.
Data: < / > 88 92 2F 00 01 00 00 00
{205} normal block at 0x002F9288, 40 bytes long.
Data: < uC > F8 75 43 00 05 00 00 00 01 00 00 00 03 00 00 00
{203} normal block at 0x002F90B8, 289 bytes long.
Data: < > 00 0D 0A 00 CD CD CD CD CD CD CD CD CD CD CD CD
{201} normal block at 0x002F7A50, 8 bytes long.
Data: < / > F8 8F 2F 00 01 00 00 00
{200} normal block at 0x002F8FF8, 40 bytes long.
Data: < uC > F8 75 43 00 06 00 00 00 01 00 00 00 01 00 00 00
{198} normal block at 0x002F8E48, 289 bytes long.
Data: < *f > 00 2A 66 00 CD CD CD CD CD CD CD CD CD CD CD CD
Object dump complete.



The last leak in the list (the first allocation though) is my input file (minus the newline). I think I see my carriage return/newline combo a few leaks later.


If you take the newline out of the input file, there are no leaks. In fact it got to the point that if I changed one thing about any of the files (grammar, main.cpp, or input file), the leaks went away.


Thanks in advance for your help.


Tim Stewart

   <<Less
About | Sitemap | Contact