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