Re: g_error_free() warning on null pointer
- From: Michael McConville <mmcconv1 sccs swarthmore edu>
- To: "Jasper St. Pierre" <jstpierre mecheye net>
- Cc: gtk-devel-list <gtk-devel-list gnome org>
- Subject: Re: g_error_free() warning on null pointer
- Date: Sat, 29 Aug 2015 14:35:15 -0400
Jasper St. Pierre wrote:
Michael McConville wrote:
Nicolas George wrote:
But maybe I am forgetting another case: can you imagine a code snippet
where g_error_free(error) would make sense with error == NULL?
I may have already mentioned this, but the simplest example is just
adding a g_error_free() at the end of a function when adding a GError*
declaration at the beginning. This prevents an irrelevant line from
cluttering the error-handling logic and makes it more trivially obvious
to auditors that there isn't a memory leak.
But if you have an error, shouldn't you either want to a) handle it,
or b) propagate it up?
I suspect that this is almost always the case. However:
1) Sometimes you have to audit other people's code for memory leaks but
don't have the time/understanding for logic additions.
2) Even if you are handling the error, the free call is clutter.
Keeping it in the function's footer contributes readability.
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]