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: Ulf Lamping <ulf.lamping@xxxxxx>
Date: Thu, 13 Oct 2005 17:21:04 +0200

Ethereal development <ethereal-dev@xxxxxxxxxxxx> schrieb am 13.10.05 15:33:51:
>   
> 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. The problem is, if this free memory is tried to be allocated by another g_malloc(), ethereal crashes. (write error) 
> 
> By replacing g_malloc() by malloc(), when the used memory is returned to system by free(), the memory can be reallocated by another malloc() call which doesn't crash ethereal… 
> 
> Could you confirm this result? 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? 
> 

If you look at the implementation of g_malloc (and g_malloc0, ...), it will simply call malloc with a check if it returns NULL and close down the app in this case. There's no additional heap management, so your assumptions are simply incorrect, replacing g_malloc with malloc doesn't make a difference.

BTW: removing g_malloc calls won't help to avoid *all* g_malloc calls, as a lot of GLib and GTK+ functions internally use g_malloc too.

Please see also http://wiki.ethereal.com/EMEMification for some effort to reduce memory management problems.

Regards, ULFL

______________________________________________________________
Verschicken Sie romantische, coole und witzige Bilder per SMS!
Jetzt bei WEB.DE FreeMail: http://f.web.de/?mc=021193