<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Thu, Apr 23, 2015 at 12:26 PM, Rafael Espíndola <span dir="ltr"><<a href="mailto:rafael.espindola@gmail.com" target="_blank">rafael.espindola@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">On 23 April 2015 at 15:17, Rui Ueyama <<a href="mailto:ruiu@google.com">ruiu@google.com</a>> wrote:<br>
> Did you actually confirm it's leaking?<br>
><br>
> A memory buffer of an archive file is co-owned by the archive file object<br>
> and file objects create out of it using shared_ptr. Look at<br>
> instantiateMember in lib/ReaderWriter/FileArchive.cpp. If you free all<br>
> files, the memory buffer should be freed as well.<br>
<br>
</span>My patch makes it leak. Note the<br>
<br>
+      Copy.release(); //leak<br>
<br>
:-)<br></blockquote><div><br></div><div>Ah, I was looking only at the patch for LLD. Sorry. Yeah it leaks memory. </div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
The idea from the llvm side is simple. Delete that release and have<br>
AlignedMemberData own the data.<br>
<br>
>From lld it complicates --whole-archive a bit. Right now what happens is:<br>
<br>
* The Archive is created.<br>
* The members are read (with my patch any unaligned members are copied<br>
to anonymous memory).<br>
* The Archive is discarded.<br>
* Link continues using the members.<br>
<br>
One way to handle it would be to change<br>
<br>
  if (wholeArchive)<br>
    return parseMemberFiles(files);<br>
<br>
into<br>
<br>
  if (wholeArchive) {<br>
    ctx.registry().saveArchive....<br>
    return parseMemberFiles(files);<br>
   }<br>
<br>
I will try coding it to see exactly what it looks like.<br></blockquote><div><br></div><div>The other idea would be to copy a memory buffer if it's unaligned in LLD, not in LLVM, and gives the ownership of the new memory buffer to a newly-created file. But I don't know which is better (at least your idea looks more generic).</div><div><br></div><div>If we go with your idea, we should remove code to make member files co-owners of the original memory buffer because it's useless.</div></div></div></div>