[Spice-devel] [PATCH spice-server] reds: Free device chain in spice_server_destroy to avoid leaks
Frediano Ziglio
fziglio at redhat.com
Wed Jul 11 16:30:25 UTC 2018
Leak detectors did not manage to find leaks, possibly as double list
have all elements likely with a pointer to them.
The reference from the agent is necessary for inserting it into
the list.
Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
---
server/reds.c | 14 ++++++++++++++
1 file changed, 14 insertions(+)
diff --git a/server/reds.c b/server/reds.c
index f1e34529a..85043a88d 100644
--- a/server/reds.c
+++ b/server/reds.c
@@ -3132,6 +3132,7 @@ static int spice_server_char_device_add_interface(SpiceServer *reds,
return -1;
}
dev_state = attach_to_red_agent(reds, char_device);
+ g_object_ref(dev_state);
}
#ifdef USE_SMARTCARD
else if (strcmp(char_device->subtype, SUBTYPE_SMARTCARD) == 0) {
@@ -3682,6 +3683,19 @@ SPICE_GNUC_VISIBLE void spice_server_destroy(SpiceServer *reds)
}
reds_cleanup_net(reds);
g_clear_object(&reds->agent_dev);
+
+ // NOTE: don't replace with g_list_free_full as this function that passed callback
+ // don't change the list while g_object_unref in this case will change it.
+ RedCharDevice *dev;
+ GLIST_FOREACH(reds->char_devices, RedCharDevice, dev) {
+ g_object_unref(dev);
+ }
+ g_list_free(reds->char_devices);
+ reds->char_devices = NULL;
+
+ g_list_free(reds->channels);
+ reds->channels = NULL;
+
spice_buffer_free(&reds->client_monitors_config);
red_record_unref(reds->record);
reds_cleanup(reds);
--
2.17.1
More information about the Spice-devel
mailing list