[lld] r223530 - [mach-o] fix leak in atoms -> normalized

Nick Kledzik kledzik at apple.com
Fri Dec 5 14:03:28 PST 2014


Author: kledzik
Date: Fri Dec  5 16:03:28 2014
New Revision: 223530

URL: http://llvm.org/viewvc/llvm-project?rev=223530&view=rev
Log:
[mach-o] fix leak in atoms -> normalized

Modified:
    lld/trunk/lib/ReaderWriter/MachO/MachONormalizedFileFromAtoms.cpp

Modified: lld/trunk/lib/ReaderWriter/MachO/MachONormalizedFileFromAtoms.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/MachO/MachONormalizedFileFromAtoms.cpp?rev=223530&r1=223529&r2=223530&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/MachO/MachONormalizedFileFromAtoms.cpp (original)
+++ lld/trunk/lib/ReaderWriter/MachO/MachONormalizedFileFromAtoms.cpp Fri Dec  5 16:03:28 2014
@@ -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<const Atom *>     _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<AtomInfo> empty;
+    si->atomsAndOffsets.swap(empty);
+  }
+  // The SegmentInfo structs are BumpPtr allocated, but sections needs
+  // to be deleted.
+  for (SegmentInfo *sgi : _segmentInfos) {
+    std::vector<SectionInfo*> empty2;
+    sgi->sections.swap(empty2);
+  }
+}
 
 SectionInfo *Util::getRelocatableSection(DefinedAtom::ContentType type) {
   StringRef segmentName;





More information about the llvm-commits mailing list