Re: g_error_free() warning on null pointer
- Date: Sat, 15 Aug 2015 13:52:02 -0700
- From: "Jasper St. Pierre" <jstpierre@xxxxxxxxxxx>
- Subject: 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
> If you call g_error_free() on a null pointer, you'll see something like
>> (process:345): GLib-CRITICAL **: g_error_free: assertion 'error != NULL' failed
> However, POSIX specifies:
>> If ptr is a null pointer, no action shall occur.
> 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:
> gtk-devel-list mailing list
gtk-devel-list mailing list