[Geany-devel] [Patch] after g_strndup, use g_free instead of free

Colomban Wendling lists.ban at xxxxx
Sun May 16 20:40:25 UTC 2010


Le dimanche 16 mai 2010 à 19:46 +0200, Enrico Tröger a écrit :
> Just for clarity, there is no technical requirement that g_strndup() or
> similar should be followed by a g_free() instead of free().
> g_free() simply calls free() with the difference that it checks for a
> NULL pointer before which is good in most cases.
> And using g_free() there is also better for readability.
Sorry but that's not exactly true: it is in the context of Geany, but it
isn't in general. g_free() frees a memory chunk with the registered free
function in the GLib's memory VTable, which by default is libc's free()
-- and then g_free() and free() are equivalent. But if for a reason or
another the VTable is set to another one, a plain free() may be invalid
since the memory may not have been allocated by libc's malloc(),
calloc() or realloc().

And free(NULL) is always a valid call ;)

Regards,
Colomban




More information about the Devel mailing list