<div dir="ltr">Manuel, have you guys run into this sort of leak due to defaulting to -disable-free before? It certainly seems like really unexpected behavior for clang as a library.<div><br></div><div>-- Sean Silva</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Nov 10, 2014 at 9:43 AM, Mike Lewis <span dir="ltr"><<a href="mailto:mikel@arena.net" target="_blank">mikel@arena.net</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div lang="EN-US" link="blue" vlink="purple"><div><p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d">Ha, good catch. Turns out -disable-free is one of the command arguments generated by the driver code somewhere in the clang::driver::Driver::<span>BuildCompilation</span>() pipe… looks like Clang::<span>ConstructJob</span>().<u></u><u></u></span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d"><u></u> <u></u></span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d">This seems problematic for anyone using the library for multiple compilations (as is my situation) due to the implicit leakage. From the code it looks like this behavior goes away if Compilation::<span>isForDiagnostics</span>() returns true, but I have no idea what the other side effects of that check might be.<u></u><u></u></span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d"><u></u> <u></u></span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d"><u></u> <u></u></span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d">Any advice would be appreciated!<u></u><u></u></span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d"><u></u> <u></u></span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d"><u></u> <u></u></span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d"><u></u> <u></u></span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d"> - Mike<u></u><u></u></span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d"><u></u> <u></u></span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d"><u></u> <u></u></span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d"><u></u> <u></u></span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d"><u></u> <u></u></span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d"><u></u> <u></u></span></p><p class="MsoNormal"><b><span style="font-size:10.0pt;font-family:"Tahoma","sans-serif"">From:</span></b><span style="font-size:10.0pt;font-family:"Tahoma","sans-serif""> Sean Silva [mailto:<a href="mailto:chisophugis@gmail.com" target="_blank">chisophugis@gmail.com</a>] <br><b>Sent:</b> Friday, November 07, 2014 8:24 PM<br><b>To:</b> Mike Lewis<br><b>Cc:</b> <a href="mailto:cfe-dev@cs.uiuc.edu" target="_blank">cfe-dev@cs.uiuc.edu</a><br><b>Subject:</b> Re: [cfe-dev] Understanding BuryPointer and leak detection<u></u><u></u></span></p><div><div class="h5"><p class="MsoNormal"><u></u> <u></u></p><div><div><p class="MsoNormal">My understanding is that all uses of BuryPointer should be somehow guarded by getFrontendOpts().DisableFree (or CodeGenOpt.DisableFree); can you see if DisableFree is somehow being set? Check FrontendAction::EndSourceFile.<u></u><u></u></p></div><div><p class="MsoNormal"><u></u> <u></u></p></div><div><p class="MsoNormal">There is also a FIXME for some "resetAndLeak*" calls not guarded by DisableFree in FrontendAction::EndSourceFile, but unless you're doing something with AST files from libclang (is that possible?) those shouldn't be an issue.<u></u><u></u></p></div></div><div><p class="MsoNormal"><u></u> <u></u></p><div><p class="MsoNormal">On Fri, Nov 7, 2014 at 9:18 AM, Mike Lewis <<a href="mailto:mikel@arena.net" target="_blank">mikel@arena.net</a>> wrote:<u></u><u></u></p><div><div><p class="MsoNormal">Hi all,<u></u><u></u></p><p class="MsoNormal"> <u></u><u></u></p><p class="MsoNormal">I’m experimenting with libclang on Windows as a mechanism for runtime compilation of C code. So far results are encouraging, but I’m encountering a lot of rogue memory usage the longer the host app runs (and the more Clang code I call). Right now I’m relying on the Visual C++ CRT leak check functionality to monitor memory leakage; it’s crude and simplistic but highly reliable once you compensate for a couple of quirks. I should state up-front that I can confirm my results of leakage using other tools as well.<u></u><u></u></p><p class="MsoNormal"> <u></u><u></u></p><p class="MsoNormal">The CRT leak check is finding several hundred KB of leaks each time I compile a module using the embedded Clang. Strategic placement of memory breakpoints suggests that the bulk of these are due to things that are (directly or otherwise) owned by something that eventually winds up handed off to the BuryPointer() function.<u></u><u></u></p><p class="MsoNormal"> <u></u><u></u></p><p class="MsoNormal">I’ve skimmed the list history for the origins of BuryPointer, but I have to confess I’m still rather confused. From an outsider’s perspective, it seems like BuryPointer is just a way to work around having to actually clean up resources that have nontrivial ownership semantics. I gather that the purpose is to make the memory *<b>look</b>* like it isn’t leaked by ensuring that the pointers are still reachable. However, this doesn’t really change the fact that the memory is essentially no longer owned by anything (semantically) and is, at least conceptually, a genuine leak.<u></u><u></u></p><p class="MsoNormal"> <u></u><u></u></p><p class="MsoNormal">Given that my experiments show memory usage increasing linearly with the number of times I invoke libclang to do a compilation, I’m guessing that this is actually a genuine problem and that BuryPointer() is papering over the symptoms for certain leak checking tools.<u></u><u></u></p><p class="MsoNormal"> <u></u><u></u></p><p class="MsoNormal"> <u></u><u></u></p><p class="MsoNormal">So, three questions:<u></u><u></u></p><p class="MsoNormal"> <u></u><u></u></p><p class="MsoNormal">- Is my understanding of BuryPointer() correct, or is there some complexity I’m not seeing as an (admittedly naïve) outsider?<u></u><u></u></p><p class="MsoNormal"> <u></u><u></u></p><p class="MsoNormal">- Given that this represents a very real upper bound on how many times my host app can do compilations, is there any recourse for reclaiming this memory in some fashion?<u></u><u></u></p><p class="MsoNormal"> <u></u><u></u></p><p class="MsoNormal">- Would there be interest in me contributing patches to address these leaks (and others I’ve found in both Clang and LLVM), presuming that there is agreement that it’s a problem?<u></u><u></u></p><p class="MsoNormal"> <u></u><u></u></p><p class="MsoNormal"> <u></u><u></u></p><p class="MsoNormal"> <u></u><u></u></p><p class="MsoNormal"> <u></u><u></u></p><p class="MsoNormal">Thanks,<u></u><u></u></p><p class="MsoNormal"><span style="color:#888888"> <u></u><u></u></span></p><p class="MsoNormal"><span style="color:#888888"> <u></u><u></u></span></p><p class="MsoNormal"><span style="color:#888888">- Mike<u></u><u></u></span></p><p class="MsoNormal"><span style="color:#888888"> <u></u><u></u></span></p><p class="MsoNormal"><span style="color:#888888"> <u></u><u></u></span></p><p class="MsoNormal"><span style="color:#888888"> <u></u><u></u></span></p><p class="MsoNormal"><span style="color:#888888"> <u></u><u></u></span></p></div></div><p class="MsoNormal" style="margin-bottom:12.0pt"><br>_______________________________________________<br>cfe-dev mailing list<br><a href="mailto:cfe-dev@cs.uiuc.edu" target="_blank">cfe-dev@cs.uiuc.edu</a><br><a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev</a><u></u><u></u></p></div><p class="MsoNormal"><u></u> <u></u></p></div></div></div></div></div></blockquote></div><br></div>