[PATCH 5/9] Manage lifetime of spicevmc channel

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Store the channel in the char device object, and unref it in dispose.
Previously, we were just creating a channel and allowing it to leak.
There may be better long-term solutions, but this works for now.
---
 server/spicevmc.c | 25 ++++++++++++++++++++++++-
 1 file changed, 24 insertions(+), 1 deletion(-)

diff --git a/server/spicevmc.c b/server/spicevmc.c
index 0f4c618..3c5d432 100644
--- a/server/spicevmc.c
+++ b/server/spicevmc.c
@@ -71,10 +71,12 @@ typedef struct RedVmcPipeItem {
     (G_TYPE_INSTANCE_GET_CLASS((obj), RED_TYPE_CHAR_DEVICE_SPICEVMC, RedCharDeviceSpiceVmcClass))
 
 typedef struct RedCharDeviceSpiceVmc RedCharDeviceSpiceVmc;
+typedef struct RedCharDeviceSpiceVmcPrivate RedCharDeviceSpiceVmcPrivate;
 typedef struct RedCharDeviceSpiceVmcClass RedCharDeviceSpiceVmcClass;
 
 struct RedCharDeviceSpiceVmc {
     RedCharDevice parent;
+    RedCharDeviceSpiceVmcPrivate *priv;
 };
 
 struct RedCharDeviceSpiceVmcClass
@@ -82,6 +84,10 @@ struct RedCharDeviceSpiceVmcClass
     RedCharDeviceClass parent_class;
 };
 
+struct RedCharDeviceSpiceVmcPrivate {
+    RedChannel *channel;
+};
+
 static GType red_char_device_spicevmc_get_type(void) G_GNUC_CONST;
 static RedCharDevice *red_char_device_spicevmc_new(SpiceCharDeviceInstance *sin,
                                                    RedsState *reds,
@@ -856,9 +862,13 @@ RedCharDevice *spicevmc_device_connect(RedsState *reds,
                                        SpiceCharDeviceInstance *sin,
                                        uint8_t channel_type)
 {
+    RedCharDeviceSpiceVmc *dev_state;
     SpiceVmcState *state = spice_vmc_state_new(reds, channel_type, sin);
 
-    return state->chardev;
+    dev_state = RED_CHAR_DEVICE_SPICEVMC(state->chardev);
+    dev_state->priv->channel = RED_CHANNEL(state);
+
+    return RED_CHAR_DEVICE(dev_state);
 }
 
 /* Must be called from RedClient handling thread. */
@@ -905,10 +915,23 @@ SPICE_GNUC_VISIBLE void spice_server_port_event(SpiceCharDeviceInstance *sin, ui
 }
 
 static void
+red_char_device_spicevmc_dispose(GObject *object)
+{
+    RedCharDeviceSpiceVmc *self = RED_CHAR_DEVICE_SPICEVMC(object);
+
+    g_clear_object(&self->priv->channel);
+}
+
+static void
 red_char_device_spicevmc_class_init(RedCharDeviceSpiceVmcClass *klass)
 {
+    GObjectClass *object_class = G_OBJECT_CLASS(klass);
     RedCharDeviceClass *char_dev_class = RED_CHAR_DEVICE_CLASS(klass);
 
+    g_type_class_add_private(klass, sizeof (RedCharDeviceSpiceVmcPrivate));
+
+    object_class->dispose = red_char_device_spicevmc_dispose;
+
     char_dev_class->read_one_msg_from_device = spicevmc_chardev_read_msg_from_dev;
     char_dev_class->send_msg_to_client = spicevmc_chardev_send_msg_to_client;
     char_dev_class->send_tokens_to_client = spicevmc_char_dev_send_tokens_to_client;
-- 
2.7.4

_______________________________________________
Spice-devel mailing list
Spice-devel@xxxxxxxxxxxxxxxxxxxxx
https://lists.freedesktop.org/mailman/listinfo/spice-devel




[Index of Archives]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Security]     [Bugtraq]     [Linux]     [Linux OMAP]     [Linux MIPS]     [ECOS]     [Asterisk Internet PBX]     [Linux API]     [Monitors]