]> granicus.if.org Git - clang/commitdiff
Fix leak in lib/CodeGen/CGException.cpp, PR18318
authorKostya Serebryany <kcc@google.com>
Thu, 9 Jan 2014 09:22:32 +0000 (09:22 +0000)
committerKostya Serebryany <kcc@google.com>
Thu, 9 Jan 2014 09:22:32 +0000 (09:22 +0000)
Summary: This fixes the leak described in http://llvm.org/bugs/show_bug.cgi?id=18318

Reviewers: chandlerc, dblaikie

Reviewed By: chandlerc

CC: cfe-commits
Differential Revision: http://llvm-reviews.chandlerc.com/D2474

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@198857 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/CGCleanup.h
lib/CodeGen/CGException.cpp

index 1bd6bba523fbfabd3d303a83aff718f1d7b0bfcd..fed75bc9d802acf9cfa2730488b79d3c79cdd976 100644 (file)
@@ -194,6 +194,15 @@ public:
     return getHandlers()[I];
   }
 
+  // Clear all handler blocks.
+  // FIXME: it's better to always call clearHandlerBlocks in DTOR and have a
+  // 'takeHandler' or some such function which removes ownership from the
+  // EHCatchScope object if the handlers should live longer than EHCatchScope.
+  void clearHandlerBlocks() {
+    for (unsigned I = 0, N = getNumHandlers(); I != N; ++I)
+      delete getHandler(I).Block;
+  }
+
   typedef const Handler *iterator;
   iterator begin() const { return getHandlers(); }
   iterator end() const { return getHandlers() + getNumHandlers(); }
index 5acb4537f3d22e21efe34d737a766e18018e68b9..8a43794281dd6e04f9a069f8c471ed8851b48b0d 100644 (file)
@@ -1244,6 +1244,7 @@ void CodeGenFunction::ExitCXXTryStmt(const CXXTryStmt &S, bool IsFnTryBlock) {
 
   // If the catch was not required, bail out now.
   if (!CatchScope.hasEHBranches()) {
+    CatchScope.clearHandlerBlocks();
     EHStack.popCatch();
     return;
   }