[libvirt] [libvirt-glib] Add async variant of gvir_domain_get_info()

Christophe Fergeau cfergeau at redhat.com
Thu Apr 19 13:58:36 UTC 2012


On Thu, Apr 19, 2012 at 04:24:35PM +0300, Zeeshan Ali (Khattak) wrote:
> On Thu, Apr 19, 2012 at 11:52 AM, Christophe Fergeau
> <cfergeau at redhat.com> wrote:
> > On Thu, Apr 19, 2012 at 03:12:01AM +0300, Zeeshan Ali (Khattak) wrote:
> >> From: "Zeeshan Ali (Khattak)" <zeeshanak at gnome.org>
> >> +static void
> >> +gvir_domain_get_info_helper(GSimpleAsyncResult *res,
> >> +                            GObject *object,
> >> +                            GCancellable *cancellable G_GNUC_UNUSED)
> >> +{
> >> +    GVirDomain *dom = GVIR_DOMAIN(object);
> >> +    GVirDomainInfo *info;
> >> +    GError *err = NULL;
> >> +
> >> +    info = gvir_domain_get_info(dom, &err);
> >> +    if (err)
> >> +        g_simple_async_result_take_error(res, err);
> >> +    else
> >> +        g_simple_async_result_set_op_res_gpointer(res, info, NULL);
> >
> > Shouldn't the last parameter be gvir_domain_info_free?
> 
> No, we give this info to user in the finalize call:

Looking at GSimpleAsyncResult documentation and use, it seems customary to pass a
GDestroyNotify function here, and to ref the returned object in the _finish
function if needed. It seems it's perfectly valid to call
gvir_domain_get_info_async() with a NULL callback, or not to call _finish
if you are not interested in the result. If you don't pass a non-NULL
GDestroyNotify to set_op_res_gpointer, I don't see how you can avoid a
memory leak in these cases. Think also of an error (cancellation) occurring
between the call to _helper and the call to finish.

Christophe
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: not available
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20120419/e938e2c3/attachment-0001.sig>


More information about the libvir-list mailing list