compositor: add destructors to shell plugins
authorPekka Paalanen <ppaalanen@gmail.com>
Thu, 22 Dec 2011 11:43:43 +0000 (13:43 +0200)
committerPekka Paalanen <ppaalanen@gmail.com>
Mon, 2 Jan 2012 13:40:56 +0000 (15:40 +0200)
Add a new wlsc_shell API function for destroying the shell plugin
object. Helps to reduce Valgrind reports.

Signed-off-by: Pekka Paalanen <ppaalanen@gmail.com>
compositor/compositor.c
compositor/compositor.h
compositor/shell.c
compositor/tablet-shell.c

index 0fa9ed8..06ee7f3 100644 (file)
@@ -2172,6 +2172,8 @@ int main(int argc, char *argv[])
        if (xserver)
                wlsc_xserver_destroy(ec);
 
+       ec->shell->destroy(ec->shell);
+
        if (ec->has_bind_display)
                ec->unbind_display(ec->display, display);
 
index 4c011f0..8611b40 100644 (file)
@@ -161,6 +161,7 @@ struct wlsc_shell {
        void (*configure)(struct wlsc_shell *shell,
                          struct wlsc_surface *surface,
                          int32_t x, int32_t y, int32_t width, int32_t height);
+       void (*destroy)(struct wlsc_shell *shell);
 };
 
 enum {
index ee15ddf..0f44add 100644 (file)
@@ -58,7 +58,7 @@ struct wl_shell {
        struct wl_list panels;
 
        struct {
-               const char *path;
+               char *path;
                int duration;
                struct wl_resource *binding;
                struct wl_list surfaces;
@@ -123,7 +123,6 @@ shell_configuration(struct wl_shell *shell)
        shell->screensaver.duration = duration;
 
        return ret;
-       /* FIXME: free(shell->screensaver.path) on plugin fini */
 }
 
 static void
@@ -1234,6 +1233,15 @@ bind_screensaver(struct wl_client *client,
        wl_resource_destroy(resource, 0);
 }
 
+static void
+shell_destroy(struct wlsc_shell *base)
+{
+       struct wl_shell *shell = container_of(base, struct wl_shell, shell);
+
+       free(shell->screensaver.path);
+       free(shell);
+}
+
 int
 shell_init(struct wlsc_compositor *ec);
 
@@ -1252,6 +1260,7 @@ shell_init(struct wlsc_compositor *ec)
        shell->shell.unlock = unlock;
        shell->shell.map = map;
        shell->shell.configure = configure;
+       shell->shell.destroy = shell_destroy;
 
        wl_list_init(&shell->hidden_surface_list);
        wl_list_init(&shell->backgrounds);
index 54985b2..5f91209 100644 (file)
@@ -511,6 +511,16 @@ bind_shell(struct wl_client *client, void *data, uint32_t version, uint32_t id)
        wl_client_add_resource(client, &shell->resource);
 }
 
+static void
+tablet_shell_destroy(struct wlsc_shell *base)
+{
+       struct tablet_shell *shell =
+               container_of(base, struct tablet_shell, shell);
+
+       wl_event_source_remove(shell->long_press_source);
+       free(shell);
+}
+
 void
 shell_init(struct wlsc_compositor *compositor);
 
@@ -552,6 +562,7 @@ shell_init(struct wlsc_compositor *compositor)
        shell->shell.unlock = tablet_shell_unlock;
        shell->shell.map = tablet_shell_map;
        shell->shell.configure = tablet_shell_configure;
+       shell->shell.destroy = tablet_shell_destroy;
 
        launch_ux_daemon(shell);