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 <ppaalanen@gmail.com>
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 @@
 	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 @@
 
 	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 @@
 	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 @@
 	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 @@
 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 @@
 			     &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);
+}