xserver: Branch 'master' - 2 commits

Adam Jackson ajax at kemper.freedesktop.org
Mon Nov 30 08:56:46 PST 2015


 hw/xwayland/xwayland-output.c |   23 +++++++++++++++++++++++
 hw/xwayland/xwayland.c        |   35 ++++++++++++++++++++++++++++++-----
 2 files changed, 53 insertions(+), 5 deletions(-)

New commits:
commit 5b2ca3413203210d112a08a4e20d14382abae437
Author: Marek Chalupa <mchqwerty at gmail.com>
Date:   Fri Nov 27 14:27:46 2015 +0100

    xwayland: check if creating xwl_output succeeded
    
    check return values of RR.*Create calls
    
    v2. do not bail out if we don't have any output
    
    Signed-off-by: Marek Chalupa <mchqwerty at gmail.com>
    Reviewed-by: Olivier Fourdan <ofourdan at redhat.com>

diff --git a/hw/xwayland/xwayland-output.c b/hw/xwayland/xwayland-output.c
index e4623d4..260c9dc 100644
--- a/hw/xwayland/xwayland-output.c
+++ b/hw/xwayland/xwayland-output.c
@@ -240,6 +240,11 @@ xwl_output_create(struct xwl_screen *xwl_screen, uint32_t id)
 
     xwl_output->output = wl_registry_bind(xwl_screen->registry, id,
                                           &wl_output_interface, 2);
+    if (!xwl_output->output) {
+        ErrorF("Failed binding wl_output\n");
+        goto err;
+    }
+
     xwl_output->server_output_id = id;
     wl_output_add_listener(xwl_output->output, &output_listener, xwl_output);
 
@@ -247,13 +252,31 @@ xwl_output_create(struct xwl_screen *xwl_screen, uint32_t id)
 
     xwl_output->xwl_screen = xwl_screen;
     xwl_output->randr_crtc = RRCrtcCreate(xwl_screen->screen, xwl_output);
+    if (!xwl_output->randr_crtc) {
+        ErrorF("Failed creating RandR CRTC\n");
+        goto err;
+    }
+
     xwl_output->randr_output = RROutputCreate(xwl_screen->screen, name,
                                               strlen(name), xwl_output);
+    if (!xwl_output->randr_output) {
+        ErrorF("Failed creating RandR Output\n");
+        goto err;
+    }
+
     RRCrtcGammaSetSize(xwl_output->randr_crtc, 256);
     RROutputSetCrtcs(xwl_output->randr_output, &xwl_output->randr_crtc, 1);
     RROutputSetConnection(xwl_output->randr_output, RR_Connected);
 
     return xwl_output;
+
+err:
+    if (xwl_output->randr_crtc)
+        RRCrtcDestroy(xwl_output->randr_crtc);
+    if (xwl_output->output)
+        wl_output_destroy(xwl_output->output);
+    free(xwl_output);
+    return NULL;
 }
 
 void
diff --git a/hw/xwayland/xwayland.c b/hw/xwayland/xwayland.c
index 1ce5868..55bf6d0 100644
--- a/hw/xwayland/xwayland.c
+++ b/hw/xwayland/xwayland.c
@@ -421,8 +421,8 @@ registry_global(void *data, struct wl_registry *registry, uint32_t id,
             wl_registry_bind(registry, id, &wl_shell_interface, 1);
     }
     else if (strcmp(interface, "wl_output") == 0 && version >= 2) {
-        xwl_output_create(xwl_screen, id);
-        xwl_screen->expecting_event++;
+        if (xwl_output_create(xwl_screen, id))
+            xwl_screen->expecting_event++;
     }
 #ifdef GLAMOR_HAS_GBM
     else if (xwl_screen->glamor &&
commit 646ebea456b4c5251ae997eab8d9b971f97de836
Author: Marek Chalupa <mchqwerty at gmail.com>
Date:   Fri Nov 27 14:59:27 2015 +0100

    xwayland: fix memory leaks on error paths in xwl_realize_window
    
    don't leak memory when realizing window fails
    
    v2. take care of all memory allocation and return values,
        not just one leak
    
    Signed-off-by: Marek Chalupa <mchqwerty at gmail.com>
    Reviewed-by: Olivier Fourdan <ofourdan at redhat.com>

diff --git a/hw/xwayland/xwayland.c b/hw/xwayland/xwayland.c
index e31becf..1ce5868 100644
--- a/hw/xwayland/xwayland.c
+++ b/hw/xwayland/xwayland.c
@@ -233,23 +233,36 @@ xwl_realize_window(WindowPtr window)
     }
 
     xwl_window = calloc(sizeof *xwl_window, 1);
+    if (xwl_window == NULL)
+        return FALSE;
+
     xwl_window->xwl_screen = xwl_screen;
     xwl_window->window = window;
     xwl_window->surface = wl_compositor_create_surface(xwl_screen->compositor);
     if (xwl_window->surface == NULL) {
         ErrorF("wl_display_create_surface failed\n");
-        return FALSE;
+        goto err;
     }
 
     if (!xwl_screen->rootless) {
         xwl_window->shell_surface =
             wl_shell_get_shell_surface(xwl_screen->shell, xwl_window->surface);
+        if (xwl_window->shell_surface == NULL) {
+            ErrorF("Failed creating shell surface\n");
+            goto err_surf;
+        }
+
         wl_shell_surface_add_listener(xwl_window->shell_surface,
                                       &shell_surface_listener, xwl_window);
 
         wl_shell_surface_set_toplevel(xwl_window->shell_surface);
 
         region = wl_compositor_create_region(xwl_screen->compositor);
+        if (region == NULL) {
+            ErrorF("Failed creating region\n");
+            goto err_surf;
+        }
+
         wl_region_add(region, 0, 0,
                       window->drawable.width, window->drawable.height);
         wl_surface_set_opaque_region(xwl_window->surface, region);
@@ -262,17 +275,29 @@ xwl_realize_window(WindowPtr window)
 
     wl_surface_set_user_data(xwl_window->surface, xwl_window);
 
-    dixSetPrivate(&window->devPrivates, &xwl_window_private_key, xwl_window);
-
     xwl_window->damage =
         DamageCreate(damage_report, damage_destroy, DamageReportNonEmpty,
                      FALSE, screen, xwl_window);
+    if (xwl_window->damage == NULL) {
+        ErrorF("Failed creating damage\n");
+        goto err_surf;
+    }
+
     DamageRegister(&window->drawable, xwl_window->damage);
     DamageSetReportAfterOp(xwl_window->damage, TRUE);
 
+    dixSetPrivate(&window->devPrivates, &xwl_window_private_key, xwl_window);
     xorg_list_init(&xwl_window->link_damage);
 
     return ret;
+
+err_surf:
+    if (xwl_window->shell_surface)
+        wl_shell_surface_destroy(xwl_window->shell_surface);
+    wl_surface_destroy(xwl_window->surface);
+err:
+    free(xwl_window);
+    return FALSE;
 }
 
 static Bool


More information about the xorg-commit mailing list