[PATCH] D48476: Detecting leaked instructions with metadata and freeing the metadata to avoid use-after-free

Arvīds Kokins via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Jun 25 01:11:11 PDT 2018


akokins updated this revision to Diff 152629.
akokins added a comment.

Made the required changes to the diff.


https://reviews.llvm.org/D48476

Files:
  lib/IR/LLVMContextImpl.cpp


Index: lib/IR/LLVMContextImpl.cpp
===================================================================
--- lib/IR/LLVMContextImpl.cpp
+++ lib/IR/LLVMContextImpl.cpp
@@ -48,6 +48,15 @@
   while (!OwnedModules.empty())
     delete *OwnedModules.begin();
 
+#ifndef NDEBUG
+  // Drop metadata references from leaked Instructions to prevent random
+  // crashes.
+  for (auto &Pair : InstructionMetadata)
+    Pair.first->dump();
+  assert(InstructionMetadata.empty() &&
+         "Instructions with metadata have been leaked");
+#endif
+
   // Drop references for MDNodes.  Do this before Values get deleted to avoid
   // unnecessary RAUW when nodes are still unresolved.
   for (auto *I : DistinctMDNodes)


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D48476.152629.patch
Type: text/x-patch
Size: 704 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180625/c2f4e14e/attachment.bin>


More information about the llvm-commits mailing list