From 4dde2fc6f6d788f681645a3711a513085e07dc7c Mon Sep 17 00:00:00 2001 From: Pekka Paalanen Date: Thu, 19 Jan 2012 13:33:50 +0200 Subject: [PATCH] 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 --- clients/window.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/clients/window.c b/clients/window.c index 47177110..deb7a975 100644 --- a/clients/window.c +++ b/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)