[PATCH] fix a leak in CodeGenFunction::EmitSwitchStmt (detected by lsan)

Kostya Serebryany kcc at google.com
Wed Dec 25 23:53:03 PST 2013


  PTAL.
  use OwningPtr to fix the leak.
  I personally like this variant less than my first variant
  since here we construct OwningPtr from a part of JumpDest object.
  But this works too.

Hi nicholas,

http://llvm-reviews.chandlerc.com/D2472

CHANGE SINCE LAST DIFF
  http://llvm-reviews.chandlerc.com/D2472?vs=6269&id=6271#toc

Files:
  lib/CodeGen/CGStmt.cpp

Index: lib/CodeGen/CGStmt.cpp
===================================================================
--- lib/CodeGen/CGStmt.cpp
+++ lib/CodeGen/CGStmt.cpp
@@ -19,6 +19,7 @@
 #include "clang/Sema/SemaDiagnostic.h"
 #include "clang/Basic/PrettyStackTrace.h"
 #include "clang/Basic/TargetInfo.h"
+#include "llvm/ADT/OwningPtr.h"
 #include "llvm/ADT/StringExtras.h"
 #include "llvm/IR/DataLayout.h"
 #include "llvm/IR/InlineAsm.h"
@@ -1237,6 +1238,7 @@
 
 void CodeGenFunction::EmitSwitchStmt(const SwitchStmt &S) {
   JumpDest SwitchExit = getJumpDestInCurrentScope("sw.epilog");
+  OwningPtr<llvm::BasicBlock> SwitchExitOwner(SwitchExit.getBlock());
 
   RunCleanupsScope ConditionScope(*this);
 
@@ -1321,7 +1323,7 @@
   ConditionScope.ForceCleanup();
 
   // Emit continuation.
-  EmitBlock(SwitchExit.getBlock(), true);
+  EmitBlock(SwitchExitOwner.take(), true);
 
   SwitchInsn = SavedSwitchInsn;
   CaseRangeBlock = SavedCRBlock;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D2472.2.patch
Type: text/x-patch
Size: 931 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20131225/f54f4550/attachment.bin>


More information about the cfe-commits mailing list