<div dir="ltr"><div><div><div><div>Hi,<br><br></div>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:<br>
<br>clang_indexSourceFile_Impl creates llvm::MemoryBuffers with the unsaved file contents and uses MemBufferOwner to manage them.<br></div></div>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 buffers.<br>
<br></div><div>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.<br><br></div>
<div>I've attached a (potential) fix.<br><br></div><div>Cheers,<br><br></div><div>-Olivier JG<br></div></div>