From: Rafael Espindola Date: Mon, 23 Jun 2014 21:15:27 +0000 (+0000) Subject: Simplify memory management with std::unique_ptr. X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=61438b1c2636eabfa0d849224e8aa35c606959a6;p=oota-llvm.git Simplify memory management with std::unique_ptr. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@211538 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/tools/llvm-ar/llvm-ar.cpp b/tools/llvm-ar/llvm-ar.cpp index 80a977c30bc..2f0d7689b11 100644 --- a/tools/llvm-ar/llvm-ar.cpp +++ b/tools/llvm-ar/llvm-ar.cpp @@ -683,10 +683,10 @@ static void writeStringTable(raw_fd_ostream &Out, Out.seek(Pos); } -static void writeSymbolTable( - raw_fd_ostream &Out, ArrayRef Members, - ArrayRef Buffers, - std::vector > &MemberOffsetRefs) { +static void +writeSymbolTable(raw_fd_ostream &Out, ArrayRef Members, + ArrayRef> Buffers, + std::vector> &MemberOffsetRefs) { unsigned StartOffset = 0; unsigned MemberNum = 0; std::string NameBuf; @@ -696,7 +696,7 @@ static void writeSymbolTable( for (ArrayRef::iterator I = Members.begin(), E = Members.end(); I != E; ++I, ++MemberNum) { - MemoryBuffer *MemberBuffer = Buffers[MemberNum]; + MemoryBuffer *MemberBuffer = Buffers[MemberNum].get(); ErrorOr ObjOrErr = object::SymbolicFile::createSymbolicFile( MemberBuffer, false, sys::fs::file_magic::unknown, &Context); @@ -757,7 +757,7 @@ static void performWriteOperation(ArchiveOperation Operation, std::vector > MemberOffsetRefs; - std::vector MemberBuffers; + std::vector> MemberBuffers; MemberBuffers.resize(NewMembers.size()); for (unsigned I = 0, N = NewMembers.size(); I < N; ++I) { @@ -779,7 +779,7 @@ static void performWriteOperation(ArchiveOperation Operation, failIfError(MemberBufferOrErr.getError()); MemberBuffer = std::move(MemberBufferOrErr.get()); } - MemberBuffers[I] = MemberBuffer.release(); + MemberBuffers[I].reset(MemberBuffer.release()); } if (Symtab) { @@ -807,7 +807,7 @@ static void performWriteOperation(ArchiveOperation Operation, } Out.seek(Pos); - const MemoryBuffer *File = MemberBuffers[MemberNum]; + const MemoryBuffer *File = MemberBuffers[MemberNum].get(); if (I->isNewMember()) { const char *FileName = I->getNew(); const sys::fs::file_status &Status = I->getStatus(); @@ -843,10 +843,6 @@ static void performWriteOperation(ArchiveOperation Operation, Out << '\n'; } - for (unsigned I = 0, N = MemberBuffers.size(); I < N; ++I) { - delete MemberBuffers[I]; - } - Output.keep(); Out.close(); sys::fs::rename(TemporaryOutput, ArchiveName);