[Spice-devel] [PATCH spice-server] reds: Free device chain in spice_server_destroy to avoid leaks
Eduardo Lima (Etrunko)
etrunko at redhat.com
Thu Jul 12 14:06:28 UTC 2018
On 11/07/18 13:30, Frediano Ziglio wrote:
> 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;
> +
g_list_free() + NULL can be replaced with g_clear_pointer()
--
Eduardo de Barros Lima (Etrunko)
Software Engineer - RedHat
etrunko at redhat.com
More information about the Spice-devel
mailing list