[patch] BuryPointer the CXTranslationUnit when a crash has been detected

Nico Weber thakis at chromium.org
Sun May 11 11:08:50 PDT 2014


Hi Ted and Daniel,

we're trying to get clang LSan-clean: completely free of leaks (PR19521).
One of the last areas where leaks are still reported are in c-index-tests –
I believe for the tests that test crash recovery. If libclang detects that
it has crashed, it doesn't free the CXTranslationUnit
in clang_disposeTranslationUnit().

There are a few other places in clang that intentionally leak things,
so BuryPointer() (in lib/Frontend/CompilerInvocation.cpp) exists to mark
pointers that are not going to be freed. The attached patch lets
clang_disposeTranslationUnit() call BuryPointer() when it's not going to
free things.

BuryPointer only increments an atomic unsigned and then writes to a global
array indexed by said unsigned, so this should be a relatively safe thing
to do. I suppose if libclang crashes and one is very unlucky, some rogue
code could have overwritten the atomic int, but BuryPointer() does range
checking. I think this is a safe change to make, but it's tricky code so I
thought pre-commit review is the way to go here.

Thanks,
Nico
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20140511/903a2dd0/attachment.html>
-------------- next part --------------
Index: tools/libclang/CIndex.cpp
===================================================================
--- tools/libclang/CIndex.cpp	(revision 208472)
+++ tools/libclang/CIndex.cpp	(working copy)
@@ -2957,8 +2957,10 @@
     // If the translation unit has been marked as unsafe to free, just discard
     // it.
     ASTUnit *Unit = cxtu::getASTUnit(CTUnit);
-    if (Unit && Unit->isUnsafeToFree())
+    if (Unit && Unit->isUnsafeToFree()) {
+      BuryPointer(CTUnit);
       return;
+    }
 
     delete cxtu::getASTUnit(CTUnit);
     delete CTUnit->StringPool;


More information about the cfe-commits mailing list