<div dir="ltr">When I run clang-tidy on OS X 10.9.3, I immediately get this output:<div><br></div><div><div><font face="courier new, monospace">clang-tidy(97903,0x7fff782fb310) malloc: *** error for object 0x7fff5fbfecd0: pointer being freed was not allocated</font></div>
<div><font face="courier new, monospace">*** set a breakpoint in malloc_error_break to debug</font></div></div><div><br></div><div>This occurs inside the destructor of ClangTidyDiagnosticConsumer. Here's my callstack:</div>
<div><br></div><div><div><font face="courier new, monospace">#4<span class="" style="white-space:pre">  </span>0x000000010058e3e2 in ~ClangTidyDiagnosticConsumer at /Users/awishnick/clang-tidy/llvm/tools/clang/tools/extra/clang-tidy/ClangTidyDiagnosticConsumer.h:190</font></div>
<div><font face="courier new, monospace">#5<span class="" style="white-space:pre">      </span>0x0000000100656a73 in std::__1::default_delete<clang::DiagnosticConsumer>::operator()(clang::DiagnosticConsumer*) const [inlined] at /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/c++/v1/memory:2426</font></div>
<div><font face="courier new, monospace">#6<span class="" style="white-space:pre">      </span>0x0000000100656a4b in std::__1::unique_ptr<clang::DiagnosticConsumer, std::__1::default_delete<clang::DiagnosticConsumer> >::reset(clang::DiagnosticConsumer*) [inlined] at /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/c++/v1/memory:2625</font></div>
<div><font face="courier new, monospace">#7<span class="" style="white-space:pre">      </span>0x00000001006569f5 in ~unique_ptr [inlined] at /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/c++/v1/memory:2593</font></div>
<div><font face="courier new, monospace">#8<span class="" style="white-space:pre">      </span>0x00000001006569f5 in ~unique_ptr [inlined] at /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/c++/v1/memory:2593</font></div>
<div><font face="courier new, monospace">#9<span class="" style="white-space:pre">      </span>0x00000001006569f5 in ~ChainedDiagnosticConsumer at /Users/awishnick/clang-tidy/llvm/tools/clang/include/clang/Frontend/ChainedDiagnosticConsumer.h:23</font></div>
<div><font face="courier new, monospace">#10<span class="" style="white-space:pre">     </span>0x0000000100656595 in ~ChainedDiagnosticConsumer at /Users/awishnick/clang-tidy/llvm/tools/clang/include/clang/Frontend/ChainedDiagnosticConsumer.h:23</font></div>
<div><font face="courier new, monospace">#11<span class="" style="white-space:pre">     </span>0x00000001006565b9 in ~ChainedDiagnosticConsumer at /Users/awishnick/clang-tidy/llvm/tools/clang/include/clang/Frontend/ChainedDiagnosticConsumer.h:23</font></div>
<div><font face="courier new, monospace">#12<span class="" style="white-space:pre">     </span>0x00000001015eec84 in ~DiagnosticsEngine at /Users/awishnick/clang-tidy/llvm/tools/clang/lib/Basic/Diagnostic.cpp:68</font></div><div>
<font face="courier new, monospace">#13<span class="" style="white-space:pre">        </span>0x00000001015eec35 in ~DiagnosticsEngine at /Users/awishnick/clang-tidy/llvm/tools/clang/lib/Basic/Diagnostic.cpp:66</font></div><div><font face="courier new, monospace">#14<span class="" style="white-space:pre">   </span>0x00000001006bd3d3 in llvm::RefCountedBase<clang::DiagnosticsEngine>::Release() const at /Users/awishnick/clang-tidy/llvm/include/llvm/ADT/IntrusiveRefCntPtr.h:55</font></div>
<div><font face="courier new, monospace">#15<span class="" style="white-space:pre">     </span>0x00000001006bd325 in llvm::IntrusiveRefCntPtrInfo<clang::DiagnosticsEngine>::release(clang::DiagnosticsEngine*) at /Users/awishnick/clang-tidy/llvm/include/llvm/ADT/IntrusiveRefCntPtr.h:90</font></div>
<div><font face="courier new, monospace">#16<span class="" style="white-space:pre">     </span>0x00000001006bd2fd in llvm::IntrusiveRefCntPtr<clang::DiagnosticsEngine>::release() at /Users/awishnick/clang-tidy/llvm/include/llvm/ADT/IntrusiveRefCntPtr.h:199</font></div>
<div><font face="courier new, monospace">#17<span class="" style="white-space:pre">     </span>0x00000001006bd2c5 in ~IntrusiveRefCntPtr at /Users/awishnick/clang-tidy/llvm/include/llvm/ADT/IntrusiveRefCntPtr.h:172</font></div>
<div><font face="courier new, monospace">#18<span class="" style="white-space:pre">     </span>0x00000001006bbe15 in ~IntrusiveRefCntPtr at /Users/awishnick/clang-tidy/llvm/include/llvm/ADT/IntrusiveRefCntPtr.h:172</font></div>
<div><font face="courier new, monospace">#19<span class="" style="white-space:pre">     </span>0x000000010065cbc1 in ~CompilerInstance at /Users/awishnick/clang-tidy/llvm/tools/clang/lib/Frontend/CompilerInstance.cpp:63</font></div>
<div><font face="courier new, monospace">#20<span class="" style="white-space:pre">     </span>0x000000010065c505 in ~CompilerInstance at /Users/awishnick/clang-tidy/llvm/tools/clang/lib/Frontend/CompilerInstance.cpp:61</font></div>
<div><font face="courier new, monospace">#21<span class="" style="white-space:pre">     </span>0x00000001005d6474 in clang::tooling::FrontendActionFactory::runInvocation(clang::CompilerInvocation*, clang::FileManager*, clang::DiagnosticConsumer*) at /Users/awishnick/clang-tidy/llvm/tools/clang/lib/Tooling/Tooling.cpp:270</font></div>
<div><font face="courier new, monospace">#22<span class="" style="white-space:pre">     </span>0x00000001005d614f in clang::tooling::ToolInvocation::runInvocation(char const*, clang::driver::Compilation*, clang::CompilerInvocation*) at /Users/awishnick/clang-tidy/llvm/tools/clang/lib/Tooling/Tooling.cpp:243</font></div>
<div><font face="courier new, monospace">#23<span class="" style="white-space:pre">     </span>0x00000001005d5290 in clang::tooling::ToolInvocation::run() at /Users/awishnick/clang-tidy/llvm/tools/clang/lib/Tooling/Tooling.cpp:229</font></div>
<div><font face="courier new, monospace">#24<span class="" style="white-space:pre">     </span>0x00000001005d7b29 in clang::tooling::ClangTool::run(clang::tooling::ToolAction*) at /Users/awishnick/clang-tidy/llvm/tools/clang/lib/Tooling/Tooling.cpp:360</font></div>
<div><font face="courier new, monospace">#25<span class="" style="white-space:pre">     </span>0x0000000100566cd2 in clang::tidy::runClangTidy(clang::tidy::ClangTidyOptionsProvider*, clang::tooling::CompilationDatabase const&, llvm::ArrayRef<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >, std::__1::vector<clang::tidy::ClangTidyError, std::__1::allocator<clang::tidy::ClangTidyError> >*) at /Users/awishnick/clang-tidy/llvm/tools/clang/tools/extra/clang-tidy/ClangTidy.cpp:345</font></div>
<div><font face="courier new, monospace">#26<span class="" style="white-space:pre">     </span>0x0000000100002a96 in main at /Users/awishnick/clang-tidy/llvm/tools/clang/tools/extra/clang-tidy/tool/ClangTidyMain.cpp:145</font></div>
</div><div><br></div><div>In short, it appears that ClangTool takes ownership of the diagnostic consumer, but it's being allocated on the stack. My fix is to allocate it on the heap instead. I've attached my patch. Please let me know if this assessment is incorrect, or if you'd like me to go about this differently.</div>
<div><br></div><div>Thanks!<br>Aaron</div><div><br></div></div>