On Sun, 30 Nov 2003, Peter Moulder wrote:
This is a low-priority cleanup that may be objectionable, so I'll post here first.
According to the g_free documentation, g_free accepts a NULL argument (as a no-op), yet much code explicitly checks for NULL before calling g_free.
Disadvantage of the transformation:
Involves a function call even in the NULL case (unless g_free is a macro or inline function that tests for NULL before passing to the "real" version). I've left a couple of places untransformed where it looks like NULL has a significant probability. If NULL is unlikely, then we're better off having more readable code [and saving a couple of bytes of object code].
May make diff3 against sodipodi code harder.
Strong candidates for applying the transformation are where the tested pointer is something long like `style->text->font_family.value', and src/module.c where it uses a IF_NOT_NULL_FREE macro.
Btw, some (but not all) of the searching for this pattern was using a regexp to reduce the probability of accidentally transforming `if (foo) g_free (bar)' for distinct `foo' and `bar'.
Any comments on where this transformation (removing the `if') should be applied? In absence of comments, I'll probably commit the patch in its current form (other than ChangeLog date).
pjrm.
Thanks for identifying the concerns about this and posting it as a patch before applying it. It looks like you've researched the change well, and I don't have any issues with applying it. As a fringe benefit, it looks like this also eliminates a good chunk of the bracket-less if's that makes Jon Cruz squeal. ;-)
Bryce