[Spice-devel] [PATCH spice-gtk 2/3] usb-device-manager: Don't show an error dialog on a cancelled device open

Marc-André Lureau mlureau at redhat.com
Mon Nov 21 06:04:01 PST 2011


Hi

> >> +    if (err)
> >> +        g_error_free(err);
> >
> > In general, we should favor g_clear_error(), which is also NULL
> > tolerant.
> 
> Hmm, I checked the docs before doing things this way and the docs
> say:
> 
> void                g_clear_error                       (GError
> **err);
> 
> If err is NULL, does nothing. If err is non-NULL, calls
> g_error_free() on *err and sets *err to NULL.
> 
> So this means that **err may by NULL, but *err will get passed to
> g_error_free(), which is not NULL tolerant (I did check that).
> 
> I also just checked the actual code for g_clear_error and the
> documentation
> is correct, so using g_clear_error(&err) instead of:
>      if (err)
>          g_error_free(err);
> Will cause g_error_free to get called with a NULL, which it does not
> like.

http://git.gnome.org/browse/glib/tree/glib/gerror.c#n623

void
g_clear_error (GError **err)
{
  if (err && *err)
    {
      g_error_free (*err);
      *err = NULL;
    }
}

I don't see how g_error_free() can be called with NULL.

regards


More information about the Spice-devel mailing list