Re: g_error_free() warning on null pointer
- From: Christian Hergert <christian hergert me>
- To: gtk-devel-list gnome org
- Subject: Re: g_error_free() warning on null pointer
- Date: Sat, 15 Aug 2015 17:09:01 -0700
Hi,
On 08/15/2015 02:54 PM, Michael McConville wrote:
Rather than strange, I'd say it was intentional and insightful. In
function bodies, you often have pointers that are used in conditions and
may or may not be null. There's a very easy and clean way to deal with
this: initialize them to NULL at the beginning and free them at the end.
Freeing conditionally in the body can be awkward and often leads to
memory leaks. I can send you a few examples from the Pidgin codebase if
you're interested.
Try g_clear_error(&error) instead of g_error_free(error) to get the
effect you want.
If you have a modern compiler/GLib, you can use g_autoptr() as well. I
usually avoid this with GError though, in case it gets used in multiple
paths.
-- Christian
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]