diff options
author | Dan Liew <delcypher@gmail.com> | 2015-12-23 11:36:57 +0000 |
---|---|---|
committer | Dan Liew <delcypher@gmail.com> | 2015-12-23 11:36:57 +0000 |
commit | 3159c9189eed89076d22d8edb7c07a91cb7a1155 (patch) | |
tree | d0d77ddb1672fe12af4839217dbfc67d3bc80dcf | |
parent | 55944ebb2f05e4954a40dcf95af362e7a550a2f4 (diff) | |
parent | f5ff9cbb0e7d5c34569b3d819823751be4ffcf34 (diff) | |
download | klee-3159c9189eed89076d22d8edb7c07a91cb7a1155.tar.gz |
Merge pull request #321 from delcypher/fix_parser_leak
Fix a leak detected by ASan in the KQuery parser where on destruction of
-rw-r--r-- | lib/Expr/Parser.cpp | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/lib/Expr/Parser.cpp b/lib/Expr/Parser.cpp index 854f6d52..e914cb80 100644 --- a/lib/Expr/Parser.cpp +++ b/lib/Expr/Parser.cpp @@ -331,6 +331,8 @@ namespace { MaxErrors(~0u), NumErrors(0) {} + virtual ~ParserImpl(); + /// Initialize - Initialize the parsing state. This must be called /// prior to the start of parsing. void Initialize() { @@ -1561,6 +1563,36 @@ void ParserImpl::Error(const char *Message, const Token &At) { llvm::errs() << '\n'; } +ParserImpl::~ParserImpl() { + // Free identifiers + // + // Note the Identifiers are not disjoint across the symbol + // tables so we need to keep track of what has freed to + // avoid doing a double free. + std::set<const Identifier*> freedNodes; + for (IdentifierTabTy::iterator pi = IdentifierTab.begin(), + pe = IdentifierTab.end(); + pi != pe; ++pi) { + const Identifier* id = pi->second; + if (freedNodes.insert(id).second) + delete id; + } + for (ExprSymTabTy::iterator pi = ExprSymTab.begin(), + pe = ExprSymTab.end(); + pi != pe; ++pi) { + const Identifier* id = pi->first; + if (freedNodes.insert(id).second) + delete id; + } + for (VersionSymTabTy::iterator pi = VersionSymTab.begin(), + pe = VersionSymTab.end(); + pi != pe; ++pi) { + const Identifier* id = pi->first; + if (freedNodes.insert(id).second) + delete id; + } +} + // AST API // FIXME: Move out of parser. |