From 35ce06d4aec38f98f1fd2bf57c2aa89ae48f7702 Mon Sep 17 00:00:00 2001 From: Pekka Paalanen Date: Tue, 3 Jan 2012 11:39:13 +0200 Subject: [PATCH] compositor: add screenshooter destructor Nothing was freeing the allocation from screenshooter_create(). Add enough boilerplate, that we can free it. Fixes a Valgrind leak. Signed-off-by: Pekka Paalanen --- compositor/compositor.c | 5 ++++- compositor/compositor.h | 9 ++++++++- compositor/screenshooter.c | 21 ++++++++++++++++----- 3 files changed, 28 insertions(+), 7 deletions(-) diff --git a/compositor/compositor.c b/compositor/compositor.c index d710d5f..4800971 100644 --- a/compositor/compositor.c +++ b/compositor/compositor.c @@ -2006,7 +2006,7 @@ wlsc_compositor_init(struct wlsc_compositor *ec, struct wl_display *display) ec->fade.animation.frame = fade_frame; wl_list_init(&ec->fade.animation.link); - screenshooter_create(ec); + ec->screenshooter = screenshooter_create(ec); wlsc_data_device_manager_init(ec); @@ -2036,6 +2036,9 @@ wlsc_compositor_shutdown(struct wlsc_compositor *ec) wl_event_source_remove(ec->idle_source); + if (ec->screenshooter) + screenshooter_destroy(ec->screenshooter); + /* Destroy all outputs associated with this compositor */ wl_list_for_each_safe(output, next, &ec->output_list, link) output->destroy(output); diff --git a/compositor/compositor.h b/compositor/compositor.h index 39cb46a..d4f44a4 100644 --- a/compositor/compositor.h +++ b/compositor/compositor.h @@ -169,6 +169,8 @@ enum { WLSC_COMPOSITOR_SLEEPING /* no rendering, no frame events */ }; +struct screenshooter; + struct wlsc_compositor { struct wl_shm *shm; struct wlsc_xserver *wxs; @@ -225,6 +227,8 @@ struct wlsc_compositor { int (*authenticate)(struct wlsc_compositor *c, uint32_t id); EGLImageKHR (*create_cursor_image)(struct wlsc_compositor *c, int32_t *width, int32_t *height); + + struct screenshooter *screenshooter; }; #define MODIFIER_CTRL (1 << 8) @@ -426,9 +430,12 @@ tty_create(struct wlsc_compositor *compositor, tty_vt_func_t vt_func, void tty_destroy(struct tty *tty); -void +struct screenshooter * screenshooter_create(struct wlsc_compositor *ec); +void +screenshooter_destroy(struct screenshooter *shooter); + uint32_t * wlsc_load_image(const char *filename, int32_t *width_arg, int32_t *height_arg, uint32_t *stride_arg); diff --git a/compositor/screenshooter.c b/compositor/screenshooter.c index 02a8d21..27967c4 100644 --- a/compositor/screenshooter.c +++ b/compositor/screenshooter.c @@ -28,6 +28,7 @@ struct screenshooter { struct wl_object base; struct wlsc_compositor *ec; + struct wl_global *global; }; static void @@ -64,20 +65,30 @@ bind_shooter(struct wl_client *client, &screenshooter_implementation, id, data); } -void +struct screenshooter * screenshooter_create(struct wlsc_compositor *ec) { struct screenshooter *shooter; shooter = malloc(sizeof *shooter); if (shooter == NULL) - return; + return NULL; shooter->base.interface = &screenshooter_interface; shooter->base.implementation = (void(**)(void)) &screenshooter_implementation; shooter->ec = ec; - wl_display_add_global(ec->wl_display, - &screenshooter_interface, shooter, bind_shooter); -}; + shooter->global = wl_display_add_global(ec->wl_display, + &screenshooter_interface, + shooter, bind_shooter); + + return shooter; +} + +void +screenshooter_destroy(struct screenshooter *shooter) +{ + wl_display_remove_global(shooter->ec->wl_display, shooter->global); + free(shooter); +} -- 2.7.4