<html>
    <head>
      <base href="https://bugs.webkit.org/" />
    </head>
    <body>
      <p>
        <div>
            <b><a class="bz_bug_link 
          bz_status_RESOLVED  bz_closed"
   title="RESOLVED FIXED - [UNIX] Simplify the file descriptor handling in SharedMemory"
   href="https://bugs.webkit.org/show_bug.cgi?id=144046#c5">Comment # 5</a>
              on <a class="bz_bug_link 
          bz_status_RESOLVED  bz_closed"
   title="RESOLVED FIXED - [UNIX] Simplify the file descriptor handling in SharedMemory"
   href="https://bugs.webkit.org/show_bug.cgi?id=144046">bug 144046</a>
              from <span class="vcard"><a class="email" href="mailto:cgarcia&#64;igalia.com" title="Carlos Garcia Campos &lt;cgarcia&#64;igalia.com&gt;"> <span class="fn">Carlos Garcia Campos</span></a>
</span></b>
        <pre>(In reply to <a href="show_bug.cgi?id=144046#c3">comment #3</a>)
<span class="quote">&gt; (In reply to <a href="show_bug.cgi?id=144046#c2">comment #2</a>)
&gt; &gt; Comment on <span class=""><a href="attachment.cgi?id=251329&amp;action=diff" name="attach_251329" title="Patch">attachment 251329</a> <a href="attachment.cgi?id=251329&amp;action=edit" title="Patch">[details]</a></span>
&gt; &gt; Patch
&gt; &gt; 
&gt; &gt; View in context:
&gt; &gt; <a href="https://bugs.webkit.org/attachment.cgi?id=251329&amp;action=review">https://bugs.webkit.org/attachment.cgi?id=251329&amp;action=review</a>
&gt; &gt; 
&gt; &gt; Looks OK.
&gt; 
&gt; Thanks for the review.
&gt; 
&gt; &gt; &gt; Source/WebKit2/Platform/IPC/Attachment.h:59
&gt; &gt; &gt; +    Attachment(const Attachment&amp;) = default;
&gt; &gt; &gt; +    Attachment&amp; operator=(Attachment&amp;) = default;
&gt; &gt; 
&gt; &gt; I think you want = delete here, not = default. It doesn’t seem OK to just
&gt; &gt; copy a file descriptor!
&gt; 
&gt; Yes, I first tried to make the class non copyable, and release the fd in the
&gt; destructor to get rid of the dispose() method and the explicit attachment
&gt; dispose made by the ArgumentEncoder, ArgumentDecoder and ConnectionUnix. But
&gt; it was not possible, or I didn't find the way. Encoding/decoding attachments
&gt; is adding them to the encoder/decoder class that take the ownership of the
&gt; file descriptors until they are passed to the platform specific send/receive
&gt; IPC methods. The thing is that Attachment::encode() is const and does
&gt; encoder.addAttachment(*this); Even if we change
&gt; ArgumentEncoder::addAttachment to receive an Attachment&amp;&amp; we can't
&gt; WTF::move(*this) in the const encode method. I'm not a C++ expert, so maybe
&gt; there's a way. In the end I forgot about that part and left the explicit
&gt; dispose, but avoiding the manual fd = -1 in several places and renaming the
&gt; confusing adoptFrom, releaseTo methods.</span >

Zan suggested to make the copy constructor and assignment private and use it only in ::encode() doing encoder.addAttachment(Attachment(*this)); That way we can ensure that any public assignment is a move. We also need to make the file descriptor member mutable and explicitly set to -1 in ::encode() since the ownership is transfered to the encoder. It's tricky, but it works. I'll submit a new bug.</pre>
        </div>
      </p>
      <hr>
      <span>You are receiving this mail because:</span>
      
      <ul>
          <li>You are the assignee for the bug.</li>
      </ul>
    </body>
</html>