Re: g_error_free on a null pointer


On 28 November 2016 at 18:48, Alex Henrie <alexhenrie24 gmail com> wrote:

Can I get some feedback on my patch for ?

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().


[@] ebassi []

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