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@gmail.com> Reviewed-by: Olivier Fourdan <ofourdan@redhat.com>
This commit is contained in:
parent
e6b106715f
commit
646ebea456
@ -233,23 +233,36 @@ xwl_realize_window(WindowPtr window)
|
|||||||
}
|
}
|
||||||
|
|
||||||
xwl_window = calloc(sizeof *xwl_window, 1);
|
xwl_window = calloc(sizeof *xwl_window, 1);
|
||||||
|
if (xwl_window == NULL)
|
||||||
|
return FALSE;
|
||||||
|
|
||||||
xwl_window->xwl_screen = xwl_screen;
|
xwl_window->xwl_screen = xwl_screen;
|
||||||
xwl_window->window = window;
|
xwl_window->window = window;
|
||||||
xwl_window->surface = wl_compositor_create_surface(xwl_screen->compositor);
|
xwl_window->surface = wl_compositor_create_surface(xwl_screen->compositor);
|
||||||
if (xwl_window->surface == NULL) {
|
if (xwl_window->surface == NULL) {
|
||||||
ErrorF("wl_display_create_surface failed\n");
|
ErrorF("wl_display_create_surface failed\n");
|
||||||
return FALSE;
|
goto err;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!xwl_screen->rootless) {
|
if (!xwl_screen->rootless) {
|
||||||
xwl_window->shell_surface =
|
xwl_window->shell_surface =
|
||||||
wl_shell_get_shell_surface(xwl_screen->shell, xwl_window->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,
|
wl_shell_surface_add_listener(xwl_window->shell_surface,
|
||||||
&shell_surface_listener, xwl_window);
|
&shell_surface_listener, xwl_window);
|
||||||
|
|
||||||
wl_shell_surface_set_toplevel(xwl_window->shell_surface);
|
wl_shell_surface_set_toplevel(xwl_window->shell_surface);
|
||||||
|
|
||||||
region = wl_compositor_create_region(xwl_screen->compositor);
|
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,
|
wl_region_add(region, 0, 0,
|
||||||
window->drawable.width, window->drawable.height);
|
window->drawable.width, window->drawable.height);
|
||||||
wl_surface_set_opaque_region(xwl_window->surface, region);
|
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);
|
wl_surface_set_user_data(xwl_window->surface, xwl_window);
|
||||||
|
|
||||||
dixSetPrivate(&window->devPrivates, &xwl_window_private_key, xwl_window);
|
|
||||||
|
|
||||||
xwl_window->damage =
|
xwl_window->damage =
|
||||||
DamageCreate(damage_report, damage_destroy, DamageReportNonEmpty,
|
DamageCreate(damage_report, damage_destroy, DamageReportNonEmpty,
|
||||||
FALSE, screen, xwl_window);
|
FALSE, screen, xwl_window);
|
||||||
|
if (xwl_window->damage == NULL) {
|
||||||
|
ErrorF("Failed creating damage\n");
|
||||||
|
goto err_surf;
|
||||||
|
}
|
||||||
|
|
||||||
DamageRegister(&window->drawable, xwl_window->damage);
|
DamageRegister(&window->drawable, xwl_window->damage);
|
||||||
DamageSetReportAfterOp(xwl_window->damage, TRUE);
|
DamageSetReportAfterOp(xwl_window->damage, TRUE);
|
||||||
|
|
||||||
|
dixSetPrivate(&window->devPrivates, &xwl_window_private_key, xwl_window);
|
||||||
xorg_list_init(&xwl_window->link_damage);
|
xorg_list_init(&xwl_window->link_damage);
|
||||||
|
|
||||||
return ret;
|
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
|
static Bool
|
||||||
|
Loading…
Reference in New Issue
Block a user