<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[203155] trunk/Source</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/203155">203155</a></dd>
<dt>Author</dt> <dd>carlosgc@webkit.org</dd>
<dt>Date</dt> <dd>2016-07-13 01:36:01 -0700 (Wed, 13 Jul 2016)</dd>
</dl>

<h3>Log Message</h3>
<pre>[GTK] WebKitGtk+ uses too many file descriptors
https://bugs.webkit.org/show_bug.cgi?id=152316

Reviewed by Michael Catanzaro.

Source/WebKit2:

The problem is that we are keeping file descriptors open in SharedMemory objects. Those objects can be kept
alive for a long time, for example in case of cached resources sent from the network process as shareable
resources. The thing is that we keep the file descriptor in the SharedMemory object only to be able to create a
Handle, duplicating the file descriptor. However, we are also assuming that we create handles for SharedMemory
objects created by another handle which is wrong. SharedMemory objects are created to map a file or data and
then a handle is created to send it to another process, or to map an existing file or data for a given handle
received from another process. They can also be created to wrap another map, but in that case we don't own the
file descritor nor the mapped data. So, after mapping from a handle, we no longer need the file descriptor, and
it can be closed to release it, while the mapped memory data will still be alive until munmap() is called. This
drastically reduces the amount of file descriptors used by WebKitGTK+.

* Platform/IPC/unix/ConnectionUnix.cpp:
(IPC::readBytesFromSocket): Use setCloseOnExec().
(IPC::Connection::createPlatformConnection): Ditto.
* Platform/SharedMemory.h:
* Platform/unix/SharedMemoryUnix.cpp:
(WebKit::SharedMemory::map): Close the file descriptor right after mmap.
(WebKit::SharedMemory::~SharedMemory): Close the file descriptor only if it hasn't been closed yet.
(WebKit::SharedMemory::createHandle): Add an ASSERT to ensure we only try to create a handle for SharedMemory
objects having a valid file descriptor. Use dupCloseOnExec() to duplicate the handle and set the close on exec flag.
* UIProcess/Launcher/gtk/ProcessLauncherGtk.cpp:
(WebKit::ProcessLauncher::launchProcess): Use setCloseOnExec().

Source/WTF:

Add helper functions to duplicate a file descriptor setting close on exec flag, and also to set close on exec
flag to an existing file descriptor.

* wtf/UniStdExtras.h:
* wtf/UniStdExtras.cpp
(WTF::setCloseOnExec):
(WTF::dupCloseOnExec):</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWTFChangeLog">trunk/Source/WTF/ChangeLog</a></li>
<li><a href="#trunkSourceWTFwtfPlatformEflcmake">trunk/Source/WTF/wtf/PlatformEfl.cmake</a></li>
<li><a href="#trunkSourceWTFwtfPlatformGTKcmake">trunk/Source/WTF/wtf/PlatformGTK.cmake</a></li>
<li><a href="#trunkSourceWTFwtfUniStdExtrash">trunk/Source/WTF/wtf/UniStdExtras.h</a></li>
<li><a href="#trunkSourceWebKit2ChangeLog">trunk/Source/WebKit2/ChangeLog</a></li>
<li><a href="#trunkSourceWebKit2PlatformIPCunixConnectionUnixcpp">trunk/Source/WebKit2/Platform/IPC/unix/ConnectionUnix.cpp</a></li>
<li><a href="#trunkSourceWebKit2PlatformSharedMemoryh">trunk/Source/WebKit2/Platform/SharedMemory.h</a></li>
<li><a href="#trunkSourceWebKit2PlatformunixSharedMemoryUnixcpp">trunk/Source/WebKit2/Platform/unix/SharedMemoryUnix.cpp</a></li>
<li><a href="#trunkSourceWebKit2UIProcessLaunchergtkProcessLauncherGtkcpp">trunk/Source/WebKit2/UIProcess/Launcher/gtk/ProcessLauncherGtk.cpp</a></li>
</ul>

<h3>Added Paths</h3>
<ul>
<li><a href="#trunkSourceWTFwtfUniStdExtrascpp">trunk/Source/WTF/wtf/UniStdExtras.cpp</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWTFChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WTF/ChangeLog (203154 => 203155)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WTF/ChangeLog        2016-07-13 07:21:37 UTC (rev 203154)
+++ trunk/Source/WTF/ChangeLog        2016-07-13 08:36:01 UTC (rev 203155)
</span><span class="lines">@@ -1,3 +1,18 @@
</span><ins>+2016-07-13  Carlos Garcia Campos  &lt;cgarcia@igalia.com&gt;
+
+        [GTK] WebKitGtk+ uses too many file descriptors
+        https://bugs.webkit.org/show_bug.cgi?id=152316
+
+        Reviewed by Michael Catanzaro.
+
+        Add helper functions to duplicate a file descriptor setting close on exec flag, and also to set close on exec
+        flag to an existing file descriptor.
+
+        * wtf/UniStdExtras.h:
+        * wtf/UniStdExtras.cpp
+        (WTF::setCloseOnExec):
+        (WTF::dupCloseOnExec):
+
</ins><span class="cx"> 2016-07-12  Benjamin Poulain  &lt;bpoulain@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         [JSC] Array.prototype.join() fails some conformance tests
</span></span></pre></div>
<a id="trunkSourceWTFwtfPlatformEflcmake"></a>
<div class="modfile"><h4>Modified: trunk/Source/WTF/wtf/PlatformEfl.cmake (203154 => 203155)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WTF/wtf/PlatformEfl.cmake        2016-07-13 07:21:37 UTC (rev 203154)
+++ trunk/Source/WTF/wtf/PlatformEfl.cmake        2016-07-13 08:36:01 UTC (rev 203155)
</span><span class="lines">@@ -1,5 +1,6 @@
</span><span class="cx"> list(APPEND WTF_SOURCES
</span><span class="cx">     PlatformUserPreferredLanguagesUnix.cpp
</span><ins>+    UniStdExtras.cpp
</ins><span class="cx"> 
</span><span class="cx">     text/efl/TextBreakIteratorInternalICUEfl.cpp
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWTFwtfPlatformGTKcmake"></a>
<div class="modfile"><h4>Modified: trunk/Source/WTF/wtf/PlatformGTK.cmake (203154 => 203155)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WTF/wtf/PlatformGTK.cmake        2016-07-13 07:21:37 UTC (rev 203154)
+++ trunk/Source/WTF/wtf/PlatformGTK.cmake        2016-07-13 08:36:01 UTC (rev 203155)
</span><span class="lines">@@ -8,6 +8,7 @@
</span><span class="cx">     glib/MainThreadGLib.cpp
</span><span class="cx">     glib/RunLoopGLib.cpp
</span><span class="cx">     PlatformUserPreferredLanguagesUnix.cpp
</span><ins>+    UniStdExtras.cpp
</ins><span class="cx"> 
</span><span class="cx">     text/gtk/TextBreakIteratorInternalICUGtk.cpp
</span><span class="cx"> )
</span></span></pre></div>
<a id="trunkSourceWTFwtfUniStdExtrascppfromrev203154trunkSourceWTFwtfUniStdExtrash"></a>
<div class="copfile"><h4>Copied: trunk/Source/WTF/wtf/UniStdExtras.cpp (from rev 203154, trunk/Source/WTF/wtf/UniStdExtras.h) (0 => 203155)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WTF/wtf/UniStdExtras.cpp                                (rev 0)
+++ trunk/Source/WTF/wtf/UniStdExtras.cpp        2016-07-13 08:36:01 UTC (rev 203155)
</span><span class="lines">@@ -0,0 +1,67 @@
</span><ins>+/*
+ * Copyright (C) 2016 Igalia S.L.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include &quot;config.h&quot;
+#include &quot;UniStdExtras.h&quot;
+
+#include &lt;fcntl.h&gt;
+
+namespace WTF {
+
+bool setCloseOnExec(int fileDescriptor)
+{
+    int returnValue = -1;
+    do {
+        int flags = fcntl(fileDescriptor, F_GETFD);
+        if (flags != -1)
+            returnValue = fcntl(fileDescriptor, F_SETFD, flags | FD_CLOEXEC);
+    } while (returnValue == -1 &amp;&amp; errno == EINTR);
+
+    return returnValue != -1;
+}
+
+int dupCloseOnExec(int fileDescriptor)
+{
+    int duplicatedFileDescriptor = -1;
+#ifdef F_DUPFD_CLOEXEC
+    while ((duplicatedFileDescriptor = fcntl(fileDescriptor, F_DUPFD_CLOEXEC, 0)) == -1 &amp;&amp; errno == EINTR) { }
+    if (duplicatedFileDescriptor != -1)
+        return duplicatedFileDescriptor;
+
+#endif
+
+    while ((duplicatedFileDescriptor = dup(fileDescriptor)) == -1 &amp;&amp; errno == EINTR) { }
+    if (duplicatedFileDescriptor == -1)
+        return -1;
+
+    if (!setCloseOnExec(duplicatedFileDescriptor)) {
+        closeWithRetry(duplicatedFileDescriptor);
+        return -1;
+    }
+
+    return duplicatedFileDescriptor;
+}
+
+} // namespace WTF
</ins></span></pre></div>
<a id="trunkSourceWTFwtfUniStdExtrash"></a>
<div class="modfile"><h4>Modified: trunk/Source/WTF/wtf/UniStdExtras.h (203154 => 203155)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WTF/wtf/UniStdExtras.h        2016-07-13 07:21:37 UTC (rev 203154)
+++ trunk/Source/WTF/wtf/UniStdExtras.h        2016-07-13 08:36:01 UTC (rev 203155)
</span><span class="lines">@@ -31,6 +31,9 @@
</span><span class="cx"> 
</span><span class="cx"> namespace WTF {
</span><span class="cx"> 
</span><ins>+bool setCloseOnExec(int fileDescriptor);
+int dupCloseOnExec(int fileDescriptor);
+
</ins><span class="cx"> inline int closeWithRetry(int fileDescriptor)
</span><span class="cx"> {
</span><span class="cx">     int ret;
</span><span class="lines">@@ -50,5 +53,7 @@
</span><span class="cx"> } // namespace WTF
</span><span class="cx"> 
</span><span class="cx"> using WTF::closeWithRetry;
</span><ins>+using WTF::setCloseOnExec;
+using WTF::dupCloseOnExec;
</ins><span class="cx"> 
</span><span class="cx"> #endif // UniStdExtras_h
</span></span></pre></div>
<a id="trunkSourceWebKit2ChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/ChangeLog (203154 => 203155)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/ChangeLog        2016-07-13 07:21:37 UTC (rev 203154)
+++ trunk/Source/WebKit2/ChangeLog        2016-07-13 08:36:01 UTC (rev 203155)
</span><span class="lines">@@ -1,3 +1,33 @@
</span><ins>+2016-07-13  Carlos Garcia Campos  &lt;cgarcia@igalia.com&gt;
+
+        [GTK] WebKitGtk+ uses too many file descriptors
+        https://bugs.webkit.org/show_bug.cgi?id=152316
+
+        Reviewed by Michael Catanzaro.
+
+        The problem is that we are keeping file descriptors open in SharedMemory objects. Those objects can be kept
+        alive for a long time, for example in case of cached resources sent from the network process as shareable
+        resources. The thing is that we keep the file descriptor in the SharedMemory object only to be able to create a
+        Handle, duplicating the file descriptor. However, we are also assuming that we create handles for SharedMemory
+        objects created by another handle which is wrong. SharedMemory objects are created to map a file or data and
+        then a handle is created to send it to another process, or to map an existing file or data for a given handle
+        received from another process. They can also be created to wrap another map, but in that case we don't own the
+        file descritor nor the mapped data. So, after mapping from a handle, we no longer need the file descriptor, and
+        it can be closed to release it, while the mapped memory data will still be alive until munmap() is called. This
+        drastically reduces the amount of file descriptors used by WebKitGTK+.
+
+        * Platform/IPC/unix/ConnectionUnix.cpp:
+        (IPC::readBytesFromSocket): Use setCloseOnExec().
+        (IPC::Connection::createPlatformConnection): Ditto.
+        * Platform/SharedMemory.h:
+        * Platform/unix/SharedMemoryUnix.cpp:
+        (WebKit::SharedMemory::map): Close the file descriptor right after mmap.
+        (WebKit::SharedMemory::~SharedMemory): Close the file descriptor only if it hasn't been closed yet.
+        (WebKit::SharedMemory::createHandle): Add an ASSERT to ensure we only try to create a handle for SharedMemory
+        objects having a valid file descriptor. Use dupCloseOnExec() to duplicate the handle and set the close on exec flag.
+        * UIProcess/Launcher/gtk/ProcessLauncherGtk.cpp:
+        (WebKit::ProcessLauncher::launchProcess): Use setCloseOnExec().
+
</ins><span class="cx"> 2016-07-12  Simon Fraser  &lt;simon.fraser@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         [iOS WK2] After zooming and when under memory pressure, page tiles sometimes don't redraw while panning
</span></span></pre></div>
<a id="trunkSourceWebKit2PlatformIPCunixConnectionUnixcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/Platform/IPC/unix/ConnectionUnix.cpp (203154 => 203155)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/Platform/IPC/unix/ConnectionUnix.cpp        2016-07-13 07:21:37 UTC (rev 203154)
+++ trunk/Source/WebKit2/Platform/IPC/unix/ConnectionUnix.cpp        2016-07-13 08:36:01 UTC (rev 203155)
</span><span class="lines">@@ -308,11 +308,9 @@
</span><span class="cx">                 memcpy(fileDescriptors.data() + previousFileDescriptorsSize, CMSG_DATA(controlMessage), sizeof(int) * fileDescriptorsCount);
</span><span class="cx"> 
</span><span class="cx">                 for (size_t i = 0; i &lt; fileDescriptorsCount; ++i) {
</span><del>-                    while (fcntl(fileDescriptors[previousFileDescriptorsSize + i], F_SETFD, FD_CLOEXEC) == -1) {
-                        if (errno != EINTR) {
-                            ASSERT_NOT_REACHED();
-                            break;
-                        }
</del><ins>+                    if (!setCloseOnExec(fileDescriptors[previousFileDescriptorsSize + i])) {
+                        ASSERT_NOT_REACHED();
+                        break;
</ins><span class="cx">                     }
</span><span class="cx">                 }
</span><span class="cx">                 break;
</span><span class="lines">@@ -532,14 +530,14 @@
</span><span class="cx"> 
</span><span class="cx">     if (options &amp; SetCloexecOnServer) {
</span><span class="cx">         // Don't expose the child socket to the parent process.
</span><del>-        while (fcntl(sockets[1], F_SETFD, FD_CLOEXEC)  == -1)
-            RELEASE_ASSERT(errno != EINTR);
</del><ins>+        if (!setCloseOnExec(sockets[1]))
+            RELEASE_ASSERT_NOT_REACHED();
</ins><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     if (options &amp; SetCloexecOnClient) {
</span><span class="cx">         // Don't expose the parent socket to potential future children.
</span><del>-        while (fcntl(sockets[0], F_SETFD, FD_CLOEXEC) == -1)
-            RELEASE_ASSERT(errno != EINTR);
</del><ins>+        if (!setCloseOnExec(sockets[0]))
+            RELEASE_ASSERT_NOT_REACHED();
</ins><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     SocketPair socketPair = { sockets[0], sockets[1] };
</span></span></pre></div>
<a id="trunkSourceWebKit2PlatformSharedMemoryh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/Platform/SharedMemory.h (203154 => 203155)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/Platform/SharedMemory.h        2016-07-13 07:21:37 UTC (rev 203154)
+++ trunk/Source/WebKit2/Platform/SharedMemory.h        2016-07-13 08:36:01 UTC (rev 203155)
</span><span class="lines">@@ -113,7 +113,7 @@
</span><span class="cx">     Protection m_protection;
</span><span class="cx"> 
</span><span class="cx"> #if USE(UNIX_DOMAIN_SOCKETS)
</span><del>-    int m_fileDescriptor;
</del><ins>+    Optional&lt;int&gt; m_fileDescriptor;
</ins><span class="cx">     bool m_isWrappingMap { false };
</span><span class="cx"> #elif OS(DARWIN)
</span><span class="cx">     mach_port_t m_port;
</span></span></pre></div>
<a id="trunkSourceWebKit2PlatformunixSharedMemoryUnixcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/Platform/unix/SharedMemoryUnix.cpp (203154 => 203155)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/Platform/unix/SharedMemoryUnix.cpp        2016-07-13 07:21:37 UTC (rev 203154)
+++ trunk/Source/WebKit2/Platform/unix/SharedMemoryUnix.cpp        2016-07-13 08:36:01 UTC (rev 203155)
</span><span class="lines">@@ -152,11 +152,14 @@
</span><span class="cx"> {
</span><span class="cx">     ASSERT(!handle.isNull());
</span><span class="cx"> 
</span><del>-    void* data = mmap(0, handle.m_attachment.size(), accessModeMMap(protection), MAP_SHARED, handle.m_attachment.fileDescriptor(), 0);
</del><ins>+    int fd = handle.m_attachment.releaseFileDescriptor();
+    void* data = mmap(0, handle.m_attachment.size(), accessModeMMap(protection), MAP_SHARED, fd, 0);
+    closeWithRetry(fd);
</ins><span class="cx">     if (data == MAP_FAILED)
</span><span class="cx">         return nullptr;
</span><span class="cx"> 
</span><del>-    RefPtr&lt;SharedMemory&gt; instance = wrapMap(data, handle.m_attachment.size(), handle.m_attachment.releaseFileDescriptor());
</del><ins>+    RefPtr&lt;SharedMemory&gt; instance = wrapMap(data, handle.m_attachment.size(), -1);
+    instance-&gt;m_fileDescriptor = Nullopt;
</ins><span class="cx">     instance-&gt;m_isWrappingMap = false;
</span><span class="cx">     return instance;
</span><span class="cx"> }
</span><span class="lines">@@ -173,34 +176,27 @@
</span><span class="cx"> 
</span><span class="cx"> SharedMemory::~SharedMemory()
</span><span class="cx"> {
</span><del>-    if (!m_isWrappingMap) {
-        munmap(m_data, m_size);
-        closeWithRetry(m_fileDescriptor);
-    }
</del><ins>+    if (m_isWrappingMap)
+        return;
+
+    munmap(m_data, m_size);
+    if (m_fileDescriptor)
+        closeWithRetry(m_fileDescriptor.value());
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> bool SharedMemory::createHandle(Handle&amp; handle, Protection)
</span><span class="cx"> {
</span><span class="cx">     ASSERT_ARG(handle, handle.isNull());
</span><ins>+    ASSERT(m_fileDescriptor);
</ins><span class="cx"> 
</span><span class="cx">     // FIXME: Handle the case where the passed Protection is ReadOnly.
</span><span class="cx">     // See https://bugs.webkit.org/show_bug.cgi?id=131542.
</span><span class="cx"> 
</span><del>-    int duplicatedHandle;
-    while ((duplicatedHandle = dup(m_fileDescriptor)) == -1) {
-        if (errno != EINTR) {
-            ASSERT_NOT_REACHED();
-            return false;
-        }
</del><ins>+    int duplicatedHandle = dupCloseOnExec(m_fileDescriptor.value());
+    if (duplicatedHandle == -1) {
+        ASSERT_NOT_REACHED();
+        return false;
</ins><span class="cx">     }
</span><del>-
-    while (fcntl(duplicatedHandle, F_SETFD, FD_CLOEXEC) == -1) {
-        if (errno != EINTR) {
-            ASSERT_NOT_REACHED();
-            closeWithRetry(duplicatedHandle);
-            return false;
-        }
-    }
</del><span class="cx">     handle.m_attachment = IPC::Attachment(duplicatedHandle, m_size);
</span><span class="cx">     return true;
</span><span class="cx"> }
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessLaunchergtkProcessLauncherGtkcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/Launcher/gtk/ProcessLauncherGtk.cpp (203154 => 203155)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/Launcher/gtk/ProcessLauncherGtk.cpp        2016-07-13 07:21:37 UTC (rev 203154)
+++ trunk/Source/WebKit2/UIProcess/Launcher/gtk/ProcessLauncherGtk.cpp        2016-07-13 08:36:01 UTC (rev 203155)
</span><span class="lines">@@ -38,6 +38,7 @@
</span><span class="cx"> #include &lt;glib.h&gt;
</span><span class="cx"> #include &lt;locale.h&gt;
</span><span class="cx"> #include &lt;wtf/RunLoop.h&gt;
</span><ins>+#include &lt;wtf/UniStdExtras.h&gt;
</ins><span class="cx"> #include &lt;wtf/glib/GLibUtilities.h&gt;
</span><span class="cx"> #include &lt;wtf/glib/GUniquePtr.h&gt;
</span><span class="cx"> #include &lt;wtf/text/CString.h&gt;
</span><span class="lines">@@ -125,8 +126,8 @@
</span><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     // Don't expose the parent socket to potential future children.
</span><del>-    while (fcntl(socketPair.client, F_SETFD, FD_CLOEXEC) == -1)
-        RELEASE_ASSERT(errno != EINTR);
</del><ins>+    if (!setCloseOnExec(socketPair.client))
+        RELEASE_ASSERT_NOT_REACHED();
</ins><span class="cx"> 
</span><span class="cx">     close(socketPair.client);
</span><span class="cx">     m_processIdentifier = pid;
</span></span></pre>
</div>
</div>

</body>
</html>