> 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 <[email protected]> > --- > hw/xwayland/xwayland.c | 31 ++++++++++++++++++++++++++++--- > 1 file changed, 28 insertions(+), 3 deletions(-) > > diff --git a/hw/xwayland/xwayland.c b/hw/xwayland/xwayland.c > index 360ae8a..55bf6d0 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 > --
Not sure we need two different labels/gotos for that, but that works, so Reviewed-by: Olivier Fourdan <[email protected]> _______________________________________________ [email protected]: X.Org development Archives: http://lists.x.org/archives/xorg-devel Info: http://lists.x.org/mailman/listinfo/xorg-devel
