Fix double-delete crash in libclang/indexing.cpp

Olivier J. G. olivier.jg at
Wed Oct 23 09:09:02 PDT 2013


While using clang_indexSourceFile(), I found that it crashes faithfully
when you give it unsaved files. Upon further inspection I found this is
apparently caused by a double-deletion:

clang_indexSourceFile_Impl creates llvm::MemoryBuffers with the unsaved
file contents and uses MemBufferOwner to manage them.
However, it also creates an ASTUnit, which by default takes ownership of
the unsaved file buffers. This leads to double deletion of the unsaved file

While it's possible to use ASTUnit::setOwnsRemappedFileBuffers(false) here,
that would mean that the unsaved file contents are no longer available to
the out_TU, which is presumably incorrect.

I've attached a (potential) fix.


-Olivier JG
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: fixindexingcrash.diff
Type: text/x-patch
Size: 1357 bytes
Desc: not available
URL: <>

More information about the cfe-commits mailing list