Re: g_error_free on a null pointer
- From: Emmanuele Bassi <ebassi gmail com>
- To: Alex Henrie <alexhenrie24 gmail com>
- Cc: GTK Devel List <gtk-devel-list gnome org>
- Subject: Re: g_error_free on a null pointer
- Date: Mon, 28 Nov 2016 18:56:53 +0000
Hi;
On 28 November 2016 at 18:48, Alex Henrie <alexhenrie24 gmail com> 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
happening.
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().
Ciao,
Emmanuele.
--
https://www.bassi.io
[@] ebassi [@gmail.com]
[
Date Prev][Date Next] [
Thread Prev][Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]