[cfe-dev] Using clang internals to preprocess a buffer, crashing with double free

Larry Gritz via cfe-dev cfe-dev at lists.llvm.org
Thu Feb 23 18:46:23 PST 2017


> On Feb 23, 2017, at 6:39 PM, James Dennett <james.dennett at gmail.com> wrote:
> 
> On Thu, Feb 23, 2017 at 4:57 PM, Jonathan Roelofs via cfe-dev <cfe-dev at lists.llvm.org <mailto:cfe-dev at lists.llvm.org>> wrote:
> 
>     const std::shared_ptr<clang::TargetOptions> &targetopts =
>           std::make_shared<clang::TargetOptions>(inst.getTargetOpts());
> 
> This line ^ is extremely suspicious. It makes a shared pointer, takes a *reference* to it, and drops it on the floor. To fix it, get rid of the 'const' and '&' from that line.
> 
> While I'd drop the '&' for clarity, that's not the bug: the temporary returned by std::make_shared will be lifetime extended here where it's bound (directly) to a reference.

Making that change did not stop the crashes, though I do agree that it's not helpful for clarity.

--
Larry Gritz
lg at larrygritz.com


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20170223/9031e9bc/attachment.html>


More information about the cfe-dev mailing list