From f26be1e9652dd6a05797986aaaaef041a82545f4 Mon Sep 17 00:00:00 2001 From: Benjamin Kramer Date: Thu, 24 Feb 2011 11:03:19 +0000 Subject: [PATCH] Plug some leaks in edis. - Don't leak parsed operands during tokenization. - Don't leak printed insts in llvm-mc. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@126381 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/MC/MCDisassembler/EDToken.cpp | 4 ++++ tools/llvm-mc/Disassembler.cpp | 10 +++++----- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/lib/MC/MCDisassembler/EDToken.cpp b/lib/MC/MCDisassembler/EDToken.cpp index 400e1649e97..de770b41ef3 100644 --- a/lib/MC/MCDisassembler/EDToken.cpp +++ b/lib/MC/MCDisassembler/EDToken.cpp @@ -194,6 +194,10 @@ int EDToken::tokenize(std::vector &tokens, tokens.push_back(token); } + // Free any parsed operands. + for (unsigned i = 0, e = parsedOperands.size(); i != e; ++i) + delete parsedOperands[i]; + return 0; } diff --git a/tools/llvm-mc/Disassembler.cpp b/tools/llvm-mc/Disassembler.cpp index 1f0850ff8b4..d98b57ebc65 100644 --- a/tools/llvm-mc/Disassembler.cpp +++ b/tools/llvm-mc/Disassembler.cpp @@ -227,8 +227,8 @@ int Disassembler::disassembleEnhanced(const std::string &TS, } EDDisassembler::initialize(); - EDDisassembler *disassembler = - EDDisassembler::getDisassembler(TS.c_str(), AS); + OwningPtr + disassembler(EDDisassembler::getDisassembler(TS.c_str(), AS)); if (disassembler == 0) { errs() << "error: couldn't get disassembler for " << TS << '\n'; @@ -236,8 +236,8 @@ int Disassembler::disassembleEnhanced(const std::string &TS, } while (ByteArray.size()) { - EDInst *inst = - disassembler->createInst(byteArrayReader, 0, &ByteArray); + OwningPtr + inst(disassembler->createInst(byteArrayReader, 0, &ByteArray)); ByteArray.erase (ByteArray.begin(), ByteArray.begin() + inst->byteSize()); @@ -330,7 +330,7 @@ int Disassembler::disassembleEnhanced(const std::string &TS, } uint64_t evaluatedResult; - void *Arg[] = { disassembler, &Out }; + void *Arg[] = { disassembler.get(), &Out }; if (operand->evaluate(evaluatedResult, verboseEvaluator, Arg)) { errs() << "error: Couldn't evaluate an operand\n"; return -1; -- 2.34.1