From 9cc1f32626efe9041f96ec57601f96ba6f3f938f Mon Sep 17 00:00:00 2001 From: Andrew Kaylor Date: Mon, 20 Apr 2015 18:48:45 +0000 Subject: [PATCH] [WinEH] Fix memory leak with catch-all mapping. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@235328 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/WinEHPrepare.cpp | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/lib/CodeGen/WinEHPrepare.cpp b/lib/CodeGen/WinEHPrepare.cpp index 4923d46c106..c540a5d92e1 100644 --- a/lib/CodeGen/WinEHPrepare.cpp +++ b/lib/CodeGen/WinEHPrepare.cpp @@ -1425,11 +1425,18 @@ void WinEHPrepare::mapLandingPadBlocks(LandingPadInst *LPad, findCleanupHandlers(Actions, BB, BB); // Add the catch handler to the action list. - // Since this is a catch-all handler, the selector won't actually appear - // in the code anywhere. ExpectedSelector here is the constant null ptr - // that we got from the landing pad instruction. - CatchHandler *Action = new CatchHandler(BB, ExpectedSelector, nullptr); - CatchHandlerMap[BB] = Action; + CatchHandler *Action = nullptr; + if (CatchHandlerMap.count(BB) && CatchHandlerMap[BB] != nullptr) { + // If the CatchHandlerMap already has an entry for this BB, re-use it. + Action = CatchHandlerMap[BB]; + assert(Action->getSelector() == ExpectedSelector); + } else { + // Since this is a catch-all handler, the selector won't actually appear + // in the code anywhere. ExpectedSelector here is the constant null ptr + // that we got from the landing pad instruction. + Action = new CatchHandler(BB, ExpectedSelector, nullptr); + CatchHandlerMap[BB] = Action; + } Actions.insertCatchHandler(Action); DEBUG(dbgs() << " Catch all handler at block " << BB->getName() << "\n"); ++HandlersFound; -- 2.11.0