[virt-tools-list] [PATCH virt-viewer 02/11] ovirt-foreign-menu: Use g_clear_pointer/g_clear_object

Christophe Fergeau cfergeau at redhat.com
Tue Jul 19 15:09:30 UTC 2016


Acked-by: Christophe Fergeau <cfergeau at redhat.com>

On Sun, Jul 17, 2016 at 11:13:02PM -0300, Eduardo Lima (Etrunko) wrote:
> Signed-off-by: Eduardo Lima (Etrunko) <etrunko at redhat.com>
> ---
>  src/ovirt-foreign-menu.c | 68 ++++++++++++------------------------------------
>  1 file changed, 16 insertions(+), 52 deletions(-)
> 
> diff --git a/src/ovirt-foreign-menu.c b/src/ovirt-foreign-menu.c
> index b0b8fec..889e7bc 100644
> --- a/src/ovirt-foreign-menu.c
> +++ b/src/ovirt-foreign-menu.c
> @@ -143,33 +143,23 @@ ovirt_foreign_menu_set_property(GObject *object, guint property_id,
>  
>      switch (property_id) {
>      case PROP_PROXY:
> -        if (priv->proxy != NULL) {
> -            g_object_unref(priv->proxy);
> -        }
> +        g_clear_object(&priv->proxy);
>          priv->proxy = g_value_dup_object(value);
>          break;
>      case PROP_API:
> -        if (priv->api != NULL) {
> -            g_object_unref(priv->api);
> -        }
> +        g_clear_object(&priv->api);
>          priv->api = g_value_dup_object(value);
>          break;
>      case PROP_VM:
> -        if (priv->vm != NULL) {
> -            g_object_unref(priv->vm);
> -        }
> +        g_clear_object(&priv->vm);
>          priv->vm = g_value_dup_object(value);
> -        g_free(priv->vm_guid);
> -        priv->vm_guid = NULL;
> +        g_clear_pointer(&priv->vm_guid, g_free);
>          if (priv->vm != NULL) {
>              g_object_get(G_OBJECT(priv->vm), "guid", &priv->vm_guid, NULL);
>          }
>          break;
>      case PROP_VM_GUID:
> -        if (priv->vm != NULL) {
> -            g_object_unref(priv->vm);
> -            priv->vm = NULL;
> -        }
> +        g_clear_object(&priv->vm);
>          g_free(priv->vm_guid);
>          priv->vm_guid = g_value_dup_string(value);
>          break;
> @@ -184,44 +174,20 @@ ovirt_foreign_menu_dispose(GObject *obj)
>  {
>      OvirtForeignMenu *self = OVIRT_FOREIGN_MENU(obj);
>  
> -    if (self->priv->proxy) {
> -        g_object_unref(self->priv->proxy);
> -        self->priv->proxy = NULL;
> -    }
> -
> -    if (self->priv->api != NULL) {
> -        g_object_unref(self->priv->api);
> -        self->priv->api = NULL;
> -    }
> -
> -    if (self->priv->vm) {
> -        g_object_unref(self->priv->vm);
> -        self->priv->vm = NULL;
> -    }
> -
> -    g_free(self->priv->vm_guid);
> -    self->priv->vm_guid = NULL;
> -
> -    if (self->priv->files) {
> -        g_object_unref(self->priv->files);
> -        self->priv->files = NULL;
> -    }
> -
> -    if (self->priv->cdrom) {
> -        g_object_unref(self->priv->cdrom);
> -        self->priv->cdrom = NULL;
> -    }
> +    g_clear_object(&self->priv->proxy);
> +    g_clear_object(&self->priv->api);
> +    g_clear_object(&self->priv->vm);
> +    g_clear_pointer(&self->priv->vm_guid, g_free);
> +    g_clear_object(&self->priv->files);
> +    g_clear_object(&self->priv->cdrom);
>  
>      if (self->priv->iso_names) {
>          g_list_free_full(self->priv->iso_names, (GDestroyNotify)g_free);
>          self->priv->iso_names = NULL;
>      }
>  
> -    g_free(self->priv->current_iso_name);
> -    self->priv->current_iso_name = NULL;
> -
> -    g_free(self->priv->next_iso_name);
> -    self->priv->next_iso_name = NULL;
> +    g_clear_pointer(&self->priv->current_iso_name, g_free);
> +    g_clear_pointer(&self->priv->next_iso_name, g_free);
>  
>      G_OBJECT_CLASS(ovirt_foreign_menu_parent_class)->dispose(obj);
>  }
> @@ -410,8 +376,8 @@ static void updated_cdrom_cb(GObject *source_object,
>                  current_file?current_file:NULL);
>          g_object_set(foreign_menu->priv->cdrom, "file", current_file, NULL);
>      }
> -    g_free(foreign_menu->priv->next_iso_name);
> -    foreign_menu->priv->next_iso_name = NULL;
> +
> +    g_clear_pointer(&foreign_menu->priv->next_iso_name, g_free);
>  }
>  
>  
> @@ -546,13 +512,11 @@ static void cdrom_file_refreshed_cb(GObject *source_object,
>      }
>  
>      /* Content of OvirtCdrom is now current */
> -    g_free(menu->priv->current_iso_name);
> +    g_clear_pointer(&menu->priv->current_iso_name, g_free);
>      if (menu->priv->cdrom != NULL) {
>          g_object_get(G_OBJECT(menu->priv->cdrom),
>                       "file", &menu->priv->current_iso_name,
>                       NULL);
> -    } else {
> -        menu->priv->current_iso_name = NULL;
>      }
>      g_object_notify(G_OBJECT(menu), "file");
>      if (menu->priv->cdrom != NULL) {
> -- 
> 2.7.4
> 
> _______________________________________________
> virt-tools-list mailing list
> virt-tools-list at redhat.com
> https://www.redhat.com/mailman/listinfo/virt-tools-list
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://listman.redhat.com/archives/virt-tools-list/attachments/20160719/c54fa48f/attachment.sig>


More information about the virt-tools-list mailing list