<!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>[184273] trunk/Source/WebCore</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/184273">184273</a></dd>
<dt>Author</dt> <dd>carlosgc@webkit.org</dd>
<dt>Date</dt> <dd>2015-05-12 23:18:22 -0700 (Tue, 12 May 2015)</dd>
</dl>

<h3>Log Message</h3>
<pre>[EGL][X11] XPixmap created in GLContextEGL::createPixmapContext() is leaked
https://bugs.webkit.org/show_bug.cgi?id=144909

Reviewed by Sergio Villar Senin and Žan Doberšek.

The pixmap is created and passed to eglCreatePixmapSurface(), but
never released. eglCreatePixmapSurface() doesn't take the
ownership of the pixmap, so we should explicitly free it when the
GLContextEGL is destroyed.

* platform/graphics/egl/GLContextEGL.cpp:
(WebCore::GLContextEGL::createPixmapContext): Use XUniquePixmap
and transfer the ownership to the context by using the new
constructor that receives a XUniquePixmap&amp;&amp;.
(WebCore::GLContextEGL::createContext): createPixmapContext() is
now only defined for X11.
(WebCore::GLContextEGL::GLContextEGL): New constructor that
receives a XUniquePixmap&amp;&amp;.
* platform/graphics/egl/GLContextEGL.h: Add new constructor and
initialize the cairo device when defined to simplify constructors.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCoreplatformgraphicseglGLContextEGLcpp">trunk/Source/WebCore/platform/graphics/egl/GLContextEGL.cpp</a></li>
<li><a href="#trunkSourceWebCoreplatformgraphicseglGLContextEGLh">trunk/Source/WebCore/platform/graphics/egl/GLContextEGL.h</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (184272 => 184273)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog        2015-05-13 05:47:03 UTC (rev 184272)
+++ trunk/Source/WebCore/ChangeLog        2015-05-13 06:18:22 UTC (rev 184273)
</span><span class="lines">@@ -1,3 +1,26 @@
</span><ins>+2015-05-12  Carlos Garcia Campos  &lt;cgarcia@igalia.com&gt;
+
+        [EGL][X11] XPixmap created in GLContextEGL::createPixmapContext() is leaked
+        https://bugs.webkit.org/show_bug.cgi?id=144909
+
+        Reviewed by Sergio Villar Senin and Žan Doberšek.
+
+        The pixmap is created and passed to eglCreatePixmapSurface(), but
+        never released. eglCreatePixmapSurface() doesn't take the
+        ownership of the pixmap, so we should explicitly free it when the
+        GLContextEGL is destroyed.
+
+        * platform/graphics/egl/GLContextEGL.cpp:
+        (WebCore::GLContextEGL::createPixmapContext): Use XUniquePixmap
+        and transfer the ownership to the context by using the new
+        constructor that receives a XUniquePixmap&amp;&amp;.
+        (WebCore::GLContextEGL::createContext): createPixmapContext() is
+        now only defined for X11.
+        (WebCore::GLContextEGL::GLContextEGL): New constructor that
+        receives a XUniquePixmap&amp;&amp;.
+        * platform/graphics/egl/GLContextEGL.h: Add new constructor and
+        initialize the cairo device when defined to simplify constructors.
+
</ins><span class="cx"> 2015-05-12  Sungmann Cho  &lt;sungmann.cho@navercorp.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Reindent DIBPixelData.h for consistency.
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformgraphicseglGLContextEGLcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/graphics/egl/GLContextEGL.cpp (184272 => 184273)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/graphics/egl/GLContextEGL.cpp        2015-05-13 05:47:03 UTC (rev 184272)
+++ trunk/Source/WebCore/platform/graphics/egl/GLContextEGL.cpp        2015-05-13 06:18:22 UTC (rev 184273)
</span><span class="lines">@@ -143,9 +143,9 @@
</span><span class="cx">     return std::make_unique&lt;GLContextEGL&gt;(context, surface, PbufferSurface);
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+#if PLATFORM(X11)
</ins><span class="cx"> std::unique_ptr&lt;GLContextEGL&gt; GLContextEGL::createPixmapContext(EGLContext sharingContext)
</span><span class="cx"> {
</span><del>-#if PLATFORM(X11)
</del><span class="cx">     EGLDisplay display = sharedEGLDisplay();
</span><span class="cx">     if (display == EGL_NO_DISPLAY)
</span><span class="cx">         return nullptr;
</span><span class="lines">@@ -165,25 +165,21 @@
</span><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     Display* x11Display = downcast&lt;PlatformDisplayX11&gt;(PlatformDisplay::sharedDisplay()).native();
</span><del>-    Pixmap pixmap = XCreatePixmap(x11Display, DefaultRootWindow(x11Display), 1, 1, depth);
</del><ins>+    XUniquePixmap pixmap = XCreatePixmap(x11Display, DefaultRootWindow(x11Display), 1, 1, depth);
</ins><span class="cx">     if (!pixmap) {
</span><span class="cx">         eglDestroyContext(display, context);
</span><span class="cx">         return nullptr;
</span><span class="cx">     }
</span><span class="cx"> 
</span><del>-    EGLSurface surface = eglCreatePixmapSurface(display, config, pixmap, 0);
-
</del><ins>+    EGLSurface surface = eglCreatePixmapSurface(display, config, pixmap.get(), 0);
</ins><span class="cx">     if (surface == EGL_NO_SURFACE) {
</span><del>-        XFreePixmap(x11Display, pixmap);
</del><span class="cx">         eglDestroyContext(display, context);
</span><span class="cx">         return nullptr;
</span><span class="cx">     }
</span><span class="cx"> 
</span><del>-    return std::make_unique&lt;GLContextEGL&gt;(context, surface, PixmapSurface);
-#else
-    return nullptr;
-#endif
</del><ins>+    return std::make_unique&lt;GLContextEGL&gt;(context, surface, WTF::move(pixmap));
</ins><span class="cx"> }
</span><ins>+#endif // PLATFORM(X11)
</ins><span class="cx"> 
</span><span class="cx"> std::unique_ptr&lt;GLContextEGL&gt; GLContextEGL::createContext(EGLNativeWindowType window, GLContext* sharingContext)
</span><span class="cx"> {
</span><span class="lines">@@ -203,12 +199,13 @@
</span><span class="cx"> 
</span><span class="cx">     EGLContext eglSharingContext = sharingContext ? static_cast&lt;GLContextEGL*&gt;(sharingContext)-&gt;m_context : 0;
</span><span class="cx">     auto context = window ? createWindowContext(window, sharingContext) : nullptr;
</span><ins>+#if PLATFORM(X11)
</ins><span class="cx">     if (!context)
</span><span class="cx">         context = createPixmapContext(eglSharingContext);
</span><del>-
</del><ins>+#endif
</ins><span class="cx">     if (!context)
</span><span class="cx">         context = createPbufferContext(eglSharingContext);
</span><del>-    
</del><ins>+
</ins><span class="cx">     return WTF::move(context);
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="lines">@@ -216,12 +213,20 @@
</span><span class="cx">     : m_context(context)
</span><span class="cx">     , m_surface(surface)
</span><span class="cx">     , m_type(type)
</span><del>-#if USE(CAIRO)
-    , m_cairoDevice(0)
-#endif
</del><span class="cx"> {
</span><ins>+    ASSERT(type != PixmapSurface);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><ins>+#if PLATFORM(X11)
+GLContextEGL::GLContextEGL(EGLContext context, EGLSurface surface, XUniquePixmap&amp;&amp; pixmap)
+    : m_context(context)
+    , m_surface(surface)
+    , m_type(PixmapSurface)
+    , m_pixmap(WTF::move(pixmap))
+{
+}
+#endif
+
</ins><span class="cx"> GLContextEGL::~GLContextEGL()
</span><span class="cx"> {
</span><span class="cx"> #if USE(CAIRO)
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformgraphicseglGLContextEGLh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/graphics/egl/GLContextEGL.h (184272 => 184273)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/graphics/egl/GLContextEGL.h        2015-05-13 05:47:03 UTC (rev 184272)
+++ trunk/Source/WebCore/platform/graphics/egl/GLContextEGL.h        2015-05-13 06:18:22 UTC (rev 184273)
</span><span class="lines">@@ -23,9 +23,12 @@
</span><span class="cx"> #if USE(EGL)
</span><span class="cx"> 
</span><span class="cx"> #include &quot;GLContext.h&quot;
</span><del>-
</del><span class="cx"> #include &lt;EGL/egl.h&gt;
</span><span class="cx"> 
</span><ins>+#if PLATFORM(X11)
+#include &quot;XUniqueResource.h&quot;
+#endif
+
</ins><span class="cx"> namespace WebCore {
</span><span class="cx"> 
</span><span class="cx"> class GLContextEGL : public GLContext {
</span><span class="lines">@@ -36,6 +39,9 @@
</span><span class="cx">     static std::unique_ptr&lt;GLContextEGL&gt; createWindowContext(EGLNativeWindowType, GLContext* sharingContext);
</span><span class="cx"> 
</span><span class="cx">     GLContextEGL(EGLContext, EGLSurface, EGLSurfaceType);
</span><ins>+#if PLATFORM(X11)
+    GLContextEGL(EGLContext, EGLSurface, XUniquePixmap&amp;&amp;);
+#endif
</ins><span class="cx">     virtual ~GLContextEGL();
</span><span class="cx">     virtual bool makeContextCurrent();
</span><span class="cx">     virtual void swapBuffers();
</span><span class="lines">@@ -53,7 +59,9 @@
</span><span class="cx"> 
</span><span class="cx"> private:
</span><span class="cx">     static std::unique_ptr&lt;GLContextEGL&gt; createPbufferContext(EGLContext sharingContext);
</span><ins>+#if PLATFORM(X11)
</ins><span class="cx">     static std::unique_ptr&lt;GLContextEGL&gt; createPixmapContext(EGLContext sharingContext);
</span><ins>+#endif
</ins><span class="cx"> 
</span><span class="cx">     static void addActiveContext(GLContextEGL*);
</span><span class="cx">     static void cleanupSharedEGLDisplay(void);
</span><span class="lines">@@ -61,8 +69,11 @@
</span><span class="cx">     EGLContext m_context;
</span><span class="cx">     EGLSurface m_surface;
</span><span class="cx">     EGLSurfaceType m_type;
</span><ins>+#if PLATFORM(X11)
+    XUniquePixmap m_pixmap;
+#endif
</ins><span class="cx"> #if USE(CAIRO)
</span><del>-    cairo_device_t* m_cairoDevice;
</del><ins>+    cairo_device_t* m_cairoDevice { nullptr };
</ins><span class="cx"> #endif
</span><span class="cx"> };
</span><span class="cx"> 
</span></span></pre>
</div>
</div>

</body>
</html>