Web lists-archives.com

Re: g_error_free() warning on null pointer

On 16/08/15 20:23, Michael McConville wrote:
> Emmanuele Bassi wrote:
>> You expected the *_free() functions in GLib to be NULL-safe. They
>> aren't, except for g_free().
> g_error_free is. Maybe others too, I haven't checked. It just prints
> annoying console warnings.

The intention throughout the GLib-based stack is that if a
g_return[_val]_if_fail() is hit, it indicates that the caller has called
the function incorrectly, in a way that is considered to be undefined
behaviour <https://en.wikipedia.org/wiki/Undefined_behavior>. Undefined
behaviour does not mean "your code will crash"; it means "any result is
valid, and it is up to the compiler or library author what happens". It
does in practice end up meaning "your code is wrong", because the
majority of the possible implementations of undefined behaviour are not
what you wanted.

As a convenience to developers and users, if "checks" are enabled in
GLib, it tries to cope with certain classes of undefined behaviour
somewhat gracefully, and emit a diagnostic (complain on stderr) rather
than just crashing. However, this is not part of GLib's API, and in
particular, if "checks" are not enabled, it will usually crash instead.

See <https://bugzilla.gnome.org/show_bug.cgi?id=660809> for more on this.

Simon McVittie
Collabora Ltd. <http://www.collabora.com/>

gtk-devel-list mailing list