From bb415eac2e79cc9c6d761cdb427693d8936b4a62 Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Wed, 13 Aug 2014 18:59:01 +0000 Subject: [PATCH] Simplify memory ownership with std::unique_ptr. llvm-svn: 215567 --- .../MCJIT/MCJITObjectCacheTest.cpp | 20 ++++++------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/llvm/unittests/ExecutionEngine/MCJIT/MCJITObjectCacheTest.cpp b/llvm/unittests/ExecutionEngine/MCJIT/MCJITObjectCacheTest.cpp index 5732908cb7c6..4c3b5cf96a24 100644 --- a/llvm/unittests/ExecutionEngine/MCJIT/MCJITObjectCacheTest.cpp +++ b/llvm/unittests/ExecutionEngine/MCJIT/MCJITObjectCacheTest.cpp @@ -25,16 +25,6 @@ class TestObjectCache : public ObjectCache { public: TestObjectCache() : DuplicateInserted(false) { } - virtual ~TestObjectCache() { - // Free any buffers we've allocated. - SmallVectorImpl::iterator it, end; - end = AllocatedBuffers.end(); - for (it = AllocatedBuffers.begin(); it != end; ++it) { - delete *it; - } - AllocatedBuffers.clear(); - } - virtual void notifyObjectCompiled(const Module *M, const MemoryBuffer *Obj) { // If we've seen this module before, note that. const std::string ModuleID = M->getModuleIdentifier(); @@ -75,14 +65,16 @@ public: private: MemoryBuffer *copyBuffer(const MemoryBuffer *Buf) { // Create a local copy of the buffer. - MemoryBuffer *NewBuffer = MemoryBuffer::getMemBufferCopy(Buf->getBuffer()); - AllocatedBuffers.push_back(NewBuffer); - return NewBuffer; + std::unique_ptr NewBuffer( + MemoryBuffer::getMemBufferCopy(Buf->getBuffer())); + MemoryBuffer *Ret = NewBuffer.get(); + AllocatedBuffers.push_back(std::move(NewBuffer)); + return Ret; } StringMap ObjMap; StringSet<> ModulesLookedUp; - SmallVector AllocatedBuffers; + SmallVector, 2> AllocatedBuffers; bool DuplicateInserted; };