diff options
author | Rafael Espindola <rafael.espindola@gmail.com> | 2014-08-13 18:59:01 +0000 |
---|---|---|
committer | Rafael Espindola <rafael.espindola@gmail.com> | 2014-08-13 18:59:01 +0000 |
commit | c73a0862330aed90370102b73a4b3ddeac10f0fe (patch) | |
tree | 2d2998beb56bab42a0ba41452080ec5410c0d6ab /unittests/ExecutionEngine | |
parent | d6448b21bf5339daaf7c0022970c0ffa9fe98a4c (diff) |
Simplify memory ownership with std::unique_ptr.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@215567 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'unittests/ExecutionEngine')
-rw-r--r-- | unittests/ExecutionEngine/MCJIT/MCJITObjectCacheTest.cpp | 20 |
1 files changed, 6 insertions, 14 deletions
diff --git a/unittests/ExecutionEngine/MCJIT/MCJITObjectCacheTest.cpp b/unittests/ExecutionEngine/MCJIT/MCJITObjectCacheTest.cpp index 5732908cb7c..4c3b5cf96a2 100644 --- a/unittests/ExecutionEngine/MCJIT/MCJITObjectCacheTest.cpp +++ b/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<MemoryBuffer *>::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<MemoryBuffer> NewBuffer( + MemoryBuffer::getMemBufferCopy(Buf->getBuffer())); + MemoryBuffer *Ret = NewBuffer.get(); + AllocatedBuffers.push_back(std::move(NewBuffer)); + return Ret; } StringMap<const MemoryBuffer *> ObjMap; StringSet<> ModulesLookedUp; - SmallVector<MemoryBuffer *, 2> AllocatedBuffers; + SmallVector<std::unique_ptr<MemoryBuffer>, 2> AllocatedBuffers; bool DuplicateInserted; }; |