From e5da30cbd3644b6ef2c0f52a7eedc676d138f9e9 Mon Sep 17 00:00:00 2001 From: Nick Kledzik Date: Fri, 5 Dec 2014 22:03:28 +0000 Subject: [PATCH] [mach-o] fix leak in atoms -> normalized llvm-svn: 223530 --- .../ReaderWriter/MachO/MachONormalizedFileFromAtoms.cpp | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/lld/lib/ReaderWriter/MachO/MachONormalizedFileFromAtoms.cpp b/lld/lib/ReaderWriter/MachO/MachONormalizedFileFromAtoms.cpp index 19a7e45..34781d5 100644 --- a/lld/lib/ReaderWriter/MachO/MachONormalizedFileFromAtoms.cpp +++ b/lld/lib/ReaderWriter/MachO/MachONormalizedFileFromAtoms.cpp @@ -95,6 +95,7 @@ class Util { public: Util(const MachOLinkingContext &ctxt) : _context(ctxt), _archHandler(ctxt.archHandler()), _entryAtom(nullptr) {} + ~Util(); void assignAtomsToSections(const lld::File &atomFile); void organizeSections(); @@ -170,6 +171,22 @@ private: std::vector _machHeaderAliasAtoms; }; +Util::~Util() { + // The SectionInfo structs are BumpPtr allocated, but atomsAndOffsets needs + // to be deleted. + for (SectionInfo *si : _sectionInfos) { + // clear() destroys vector elements, but does not deallocate. + // Instead use swap() to deallocate vector buffer. + std::vector empty; + si->atomsAndOffsets.swap(empty); + } + // The SegmentInfo structs are BumpPtr allocated, but sections needs + // to be deleted. + for (SegmentInfo *sgi : _segmentInfos) { + std::vector empty2; + sgi->sections.swap(empty2); + } +} SectionInfo *Util::getRelocatableSection(DefinedAtom::ContentType type) { StringRef segmentName; -- 2.7.4