window: destroy frame in window_destroy()

Fix a memory leak reported by Valgrind, by destroying the window
decorations widget, if it exists.

All widget pointers returned from toytoolkit to the application should
be destroyed by the application explicitly.

Signed-off-by: Pekka Paalanen <ppaalanen@gmail.com>
dev
Pekka Paalanen 13 years ago
parent 90b53815ba
commit 4dde2fc6f6
  1. 16
      clients/window.c

@ -130,6 +130,7 @@ struct window {
window_drop_handler_t drop_handler;
window_close_handler_t close_handler;
struct frame *frame;
struct widget *widget;
struct window *menu;
@ -956,6 +957,8 @@ window_create_surface(struct window *window)
cairo_surface_destroy(surface);
}
static void frame_destroy(struct frame *frame);
void
window_destroy(struct window *window)
{
@ -977,6 +980,9 @@ window_destroy(struct window *window)
input->keyboard_focus = NULL;
}
if (window->frame)
frame_destroy(window->frame);
if (window->shell_surface)
wl_shell_surface_destroy(window->shell_surface);
wl_surface_destroy(window->surface);
@ -1411,9 +1417,19 @@ frame_create(struct window *window, void *data)
widget_set_motion_handler(frame->widget, frame_motion_handler);
widget_set_button_handler(frame->widget, frame_button_handler);
window->frame = frame;
return frame->child;
}
static void
frame_destroy(struct frame *frame)
{
/* frame->child must be destroyed by the application */
widget_destroy(frame->widget);
free(frame);
}
static void
input_set_focus_widget(struct input *input, struct widget *focus,
uint32_t time, int32_t x, int32_t y)

Loading…
Cancel
Save