Re: g_error_free() warning on null pointer



Lots of things in GLib fail when passed a NULL pointer, like g_object_unref.

The idea is that passing a NULL pointer is probably a sign of a bug
somewhere, so you shouldn't do it. While the C standard's free() is
NULL-safe, I'd say that this is quite strange for the C standard,
since any other invalid pointer passed to free() would (most likely,
though yes, implementation-defined) crash.

On Sat, Aug 15, 2015 at 1:28 PM, Michael McConville
<mmcconv1 sccs swarthmore edu> wrote:
If you call g_error_free() on a null pointer, you'll see something like
this:

(process:345): GLib-CRITICAL **: g_error_free: assertion 'error != NULL' failed

However, POSIX specifies:

If ptr is a null pointer, no action shall occur.

        http://pubs.opengroup.org/onlinepubs/009695399/functions/free.html

From what I've seen, all major Unices comply with this and mention it in
their man page. While printing that warning may not be a program action,
it's definitely disconcerting and dilutes debug logs. It seems to me
that POSIX intends free() to be used in situations in which the pointer
may be null. This is common practice.

Additionally, g_clear_error() doesn't print a warning when passed NULL.

Fixing this would just involve removing this line:

        https://github.com/GNOME/glib/blob/master/glib/gerror.c#L467

Thoughts?
_______________________________________________
gtk-devel-list mailing list
gtk-devel-list gnome org
https://mail.gnome.org/mailman/listinfo/gtk-devel-list



-- 
  Jasper


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]