Re: g_error_free on a null pointer
- Date: Wed, 30 Nov 2016 22:07:08 -0700
- From: Alex Henrie <alexhenrie24@xxxxxxxxx>
- Subject: Re: g_error_free on a null pointer
2016-11-28 11:56 GMT-07:00 Emmanuele Bassi <ebassi@xxxxxxxxx>:
> On 28 November 2016 at 18:48, Alex Henrie <alexhenrie24@xxxxxxxxx> wrote:
>> Can I get some feedback on my patch for
>> https://bugzilla.gnome.org/show_bug.cgi?id=774738 ?
>> If this bug is not going to be fixed then I'll make sure to put null
>> checks before calls to g_error_free, but if it's going to be fixed
>> soon then I won't bother.
> Only `g_free()` is NULL safe because it's a wrapper around the
> system's `free()`, which must be (by C standard) NULL safe. Same goes
> for g_slice_free(), because the slab allocator can be overridden and
> go through the system allocator.
> In general, GLib free functions are not NULL-safe because they are not
> deallocating random chunks of memory: they expect a specific
> something, and if you pass NULL most likely something wrong is
> If you want to do a NULL check and NULLify a pointer, then you should
> use g_clear_pointer().
> For GError, you can use g_clear_error().
Okay, thanks for the information.
gtk-devel-list mailing list