From b5a68d2181e23094558069058663460b04b2303a Mon Sep 17 00:00:00 2001 From: Morgan Deters Date: Tue, 12 Oct 2010 21:49:07 +0000 Subject: [PATCH] fix some leaks in parser, add debug code to node manager to find more --- src/expr/node_manager.cpp | 14 ++++++++++++++ src/parser/antlr_input.cpp | 8 ++++---- src/parser/antlr_input.h | 12 +++++++----- 3 files changed, 25 insertions(+), 9 deletions(-) diff --git a/src/expr/node_manager.cpp b/src/expr/node_manager.cpp index 4e872ad5c..8ff83bb94 100644 --- a/src/expr/node_manager.cpp +++ b/src/expr/node_manager.cpp @@ -118,6 +118,20 @@ NodeManager::~NodeManager() { } poolRemove( &expr::NodeValue::s_null ); + + if(Debug.isOn("gc:leaks")) { + Debug("gc:leaks") << "still in pool:" << std::endl; + for(NodeValuePool::const_iterator i = d_nodeValuePool.begin(), + iend = d_nodeValuePool.end(); + i != iend; + ++i) { + Debug("gc:leaks") << " " << *i + << " id=" << (*i)->d_id + << " rc=" << (*i)->d_rc + << " " << **i << std::endl; + } + Debug("gc:leaks") << ":end:" << std::endl; + } } void NodeManager::reclaimZombies() { diff --git a/src/parser/antlr_input.cpp b/src/parser/antlr_input.cpp index 39c8e11b3..74157acd7 100644 --- a/src/parser/antlr_input.cpp +++ b/src/parser/antlr_input.cpp @@ -171,7 +171,7 @@ AntlrInput::AntlrInput(AntlrInputStream& inputStream, unsigned int lookahead) : d_lexer(NULL), d_parser(NULL), d_antlr3InputStream( inputStream.getAntlr3InputStream() ), - d_tokenStream(NULL) { + d_tokenBuffer(NULL) { } /* @@ -204,11 +204,11 @@ AntlrInput::Input(ExprManager* exprManager, const std::string& input, const std: */ AntlrInput::~AntlrInput() { - d_tokenStream->free(d_tokenStream); + BoundedTokenBufferFree(d_tokenBuffer); } pANTLR3_COMMON_TOKEN_STREAM AntlrInput::getTokenStream() { - return d_tokenStream; + return d_tokenBuffer->commonTstream; } void AntlrInput::lexerError(pANTLR3_BASE_RECOGNIZER recognizer) { @@ -260,7 +260,7 @@ void AntlrInput::setAntlr3Lexer(pANTLR3_LEXER pLexer) { throw ParserException("Couldn't create token buffer."); } - d_tokenStream = buffer->commonTstream; + d_tokenBuffer = buffer; // Override default lexer error reporting d_lexer->rec->reportError = &lexerError; diff --git a/src/parser/antlr_input.h b/src/parser/antlr_input.h index 82b15d199..e55e07efd 100644 --- a/src/parser/antlr_input.h +++ b/src/parser/antlr_input.h @@ -28,9 +28,10 @@ #include #include -#include "input.h" -#include "parser_options.h" -#include "parser_exception.h" +#include "parser/input.h" +#include "parser/parser_options.h" +#include "parser/parser_exception.h" +#include "parser/bounded_token_buffer.h" #include "expr/expr.h" #include "expr/expr_manager.h" #include "util/Assert.h" @@ -117,10 +118,11 @@ class AntlrInput : public Input { /** The ANTLR3 input stream associated with this input. */ pANTLR3_INPUT_STREAM d_antlr3InputStream; - /** The ANTLR3 token stream associated with this input. We only need this so we can free it on exit. + /** The ANTLR3 bounded token buffer associated with this input. + * We only need this so we can free it on exit. * This is set by setLexer. * NOTE: We assume that we can free it on exit. No sharing! */ - pANTLR3_COMMON_TOKEN_STREAM d_tokenStream; + pBOUNDED_TOKEN_BUFFER d_tokenBuffer; /** Turns an ANTLR3 exception into a message for the user and calls parseError. */ static void reportError(pANTLR3_BASE_RECOGNIZER recognizer); -- 2.30.2