[PATCH] core: reset GList pointers to NULL when necessary

Ben Chan benchan at chromium.org
Wed Mar 29 06:28:16 UTC 2017


btw, the g_list_free_full implementation seems to handle a NULL GList
argument, but the glib doc doesn't explicitly mention that.  I wonder if
it's better to add `if (glist_ptr)` check anyway.

On Tue, Mar 28, 2017 at 11:23 PM, Ben Chan <benchan at chromium.org> wrote:

> When calling g_list_free_full() to free a GList in dispose(), it is
> necessary to reset the GList pointer to NULL as dispose() may be called
> more than once.
> ---
>  src/mm-call-list.c | 1 +
>  src/mm-device.c    | 2 ++
>  src/mm-sms-list.c  | 1 +
>  3 files changed, 4 insertions(+)
>
> diff --git a/src/mm-call-list.c b/src/mm-call-list.c
> index e829ae7b..fae66035 100644
> --- a/src/mm-call-list.c
> +++ b/src/mm-call-list.c
> @@ -395,6 +395,7 @@ dispose (GObject *object)
>
>      g_clear_object (&self->priv->modem);
>      g_list_free_full (self->priv->list, g_object_unref);
> +    self->priv->list = NULL;
>
>      G_OBJECT_CLASS (mm_call_list_parent_class)->dispose (object);
>  }
> diff --git a/src/mm-device.c b/src/mm-device.c
> index aa7a27e0..1b69f3de 100644
> --- a/src/mm-device.c
> +++ b/src/mm-device.c
> @@ -647,7 +647,9 @@ dispose (GObject *object)
>
>      g_clear_object (&(self->priv->plugin));
>      g_list_free_full (self->priv->port_probes, g_object_unref);
> +    self->priv->port_probes = NULL;
>      g_list_free_full (self->priv->ignored_port_probes, g_object_unref);
> +    self->priv->ignored_port_probes = NULL;
>
>      clear_modem (self);
>
> diff --git a/src/mm-sms-list.c b/src/mm-sms-list.c
> index 03daaf24..7819b3ad 100644
> --- a/src/mm-sms-list.c
> +++ b/src/mm-sms-list.c
> @@ -451,6 +451,7 @@ dispose (GObject *object)
>
>      g_clear_object (&self->priv->modem);
>      g_list_free_full (self->priv->list, g_object_unref);
> +    self->priv->list = NULL;
>
>      G_OBJECT_CLASS (mm_sms_list_parent_class)->dispose (object);
>  }
> --
> 2.12.2.564.g063fe858b8-goog
>
> _______________________________________________
> ModemManager-devel mailing list
> ModemManager-devel at lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/modemmanager-devel
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.freedesktop.org/archives/modemmanager-devel/attachments/20170328/14cf7c75/attachment.html>


More information about the ModemManager-devel mailing list