[Spice-devel] [PATCH spice-server] inputs-channels: Remove leak using tablet device

Frediano Ziglio fziglio at redhat.com
Wed Nov 22 11:31:13 UTC 2017


Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
---
 server/inputs-channel.c   |  5 ++++
 server/tests/test-leaks.c | 66 +++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 71 insertions(+)

diff --git a/server/inputs-channel.c b/server/inputs-channel.c
index f6ad27ec..b4292f0e 100644
--- a/server/inputs-channel.c
+++ b/server/inputs-channel.c
@@ -566,6 +566,7 @@ inputs_channel_finalize(GObject *object)
     InputsChannel *self = INPUTS_CHANNEL(object);
     RedsState *reds = red_channel_get_server(RED_CHANNEL(self));
 
+    inputs_channel_detach_tablet(self, self->tablet);
     reds_core_timer_remove(reds, self->key_modifiers_timer);
 
     G_OBJECT_CLASS(inputs_channel_parent_class)->finalize(object);
@@ -652,6 +653,10 @@ int inputs_channel_has_tablet(InputsChannel *inputs)
 void inputs_channel_detach_tablet(InputsChannel *inputs, SpiceTabletInstance *tablet)
 {
     spice_printerr("");
+    if (tablet != NULL && tablet == inputs->tablet) {
+        g_free(tablet->st);
+        tablet->st = NULL;
+    }
     inputs->tablet = NULL;
 }
 
diff --git a/server/tests/test-leaks.c b/server/tests/test-leaks.c
index 7032000a..41734c57 100644
--- a/server/tests/test-leaks.c
+++ b/server/tests/test-leaks.c
@@ -178,6 +178,71 @@ static void migration_leaks(void)
     basic_event_loop_destroy();
 }
 
+static void tablet_set_logical_size(SpiceTabletInstance* sin, int width, int height)
+{
+}
+
+static void tablet_position(SpiceTabletInstance* sin, int x, int y,
+                            uint32_t buttons_state)
+{
+}
+
+static void tablet_wheel(SpiceTabletInstance* sin, int wheel,
+                         uint32_t buttons_state)
+{
+}
+
+static void tablet_buttons(SpiceTabletInstance *sin,
+                           uint32_t buttons_state)
+{
+}
+
+static const SpiceTabletInterface tablet_interface = {
+    .base = {
+        .type          = SPICE_INTERFACE_TABLET,
+        .description   = "tablet",
+        .major_version = SPICE_INTERFACE_TABLET_MAJOR,
+        .minor_version = SPICE_INTERFACE_TABLET_MINOR,
+    },
+    .set_logical_size   = tablet_set_logical_size,
+    .position           = tablet_position,
+    .wheel              = tablet_wheel,
+    .buttons            = tablet_buttons,
+};
+
+static void tablet_leaks(void)
+{
+    SpiceCoreInterface *core;
+    SpiceServer *server;
+    SpiceTabletInstance tablet;
+
+    core = basic_event_loop_init();
+    g_assert_nonnull(core);
+
+    // test if leaks without spice_server_remove_interface
+    server = spice_server_new();
+    g_assert_nonnull(server);
+    g_assert_cmpint(spice_server_init(server, core), ==, 0);
+
+    tablet.base.sif = &tablet_interface.base;
+    spice_server_add_interface(server, &tablet.base);
+
+    spice_server_destroy(server);
+
+    // test if leaks with spice_server_remove_interface
+    server = spice_server_new();
+    g_assert_nonnull(server);
+    g_assert_cmpint(spice_server_init(server, core), ==, 0);
+
+    tablet.base.sif = &tablet_interface.base;
+    spice_server_add_interface(server, &tablet.base);
+    spice_server_remove_interface(&tablet.base);
+
+    spice_server_destroy(server);
+
+    basic_event_loop_destroy();
+}
+
 int main(int argc, char *argv[])
 {
     g_test_init(&argc, &argv, NULL);
@@ -185,6 +250,7 @@ int main(int argc, char *argv[])
     g_test_add_func("/server/server leaks", server_leaks);
     g_test_add_func("/server/vmc leaks", vmc_leaks);
     g_test_add_func("/server/migration leaks", migration_leaks);
+    g_test_add_func("/server/tablet leaks", tablet_leaks);
 
     return g_test_run();
 }
-- 
2.14.3



More information about the Spice-devel mailing list