Ethereal-dev: Re: [Ethereal-dev] G_malloc vs malloc

Note: This archive is from the project's previous web site, ethereal.com. This list is no longer active.

From: Guy Harris <gharris@xxxxxxxxx>
Date: Thu, 13 Oct 2005 09:08:37 -0700
Ceyhun Seran wrote:

To avoid usage of g_malloc() which results crashes in ethereal, I replaced all g_malloc() (about 3000 occurences) by malloc and g_malloc0() by calloc. Because when the memory is allocated by a g_malloc, it is not returned to system by calling g_free() and stays in application free memory heap.
If you call g_free() on memory, that memory is handed to free().  free() 
doesn't, in most if not all implementations, "return the memory to the 
system" by making a system call; it just returns it to the free memory 
pool used by malloc() (which, as Ulf Lamping notes, is what g_malloc() 
calls).
The problem is, if this free memory is tried to be allocated by another g_malloc(), ethereal crashes. (write error)
We have not seen that problem.  I suspect most other applications using 
GLib, including those using GTK+, haven't seen it either.
If there are errors in the code *using* g_malloc() and g_free(), you 
might get those symptoms - but if there are errors in code using 
malloc() and free(), you might get the same symptoms.
And my question is :
why didn't you limit the usage of g_malloc() or why didn't you replace all g_malloc() by another suitable memory allocation function in actual release?
Because replacing *all* of them means replacing GLib and GTK+ with a 
package that doesn't use g_malloc(); as Ulf notes, GLib and GTK+ 
routines used by Ethereal use g_malloc().