[Mono-dev] [PATCH] eglib memory allocation changes

Bill Holmes billholmes54 at gmail.com
Fri Aug 1 10:30:59 EDT 2008


Hello All,

Attached is a patch to change eglib memory allocation methods to
return NULL if the size is passed in is zero.  If this is approved I
would also like to put it into the 2.0 branch.

I tracked a bug to load_modules in image.c.  In this particular case
image->modules was being set to a non-null value when the
image->module_count was equal to 0.  There is another area of the code
later that checks the modules but not he module_count and causes an
assert.  I could have simply changed this code but after reading the
glib documentation I believe that this patch is the right change.
Also there may be more critical areas that I have not discovered yet
that could hit this problem.

Documentation

malloc
If size is 0, either a null pointer or a unique pointer that can be
successfully passed to free() shall be returned.

calloc
If either nelem or elsize is 0, then either a null pointer or a unique
pointer value that can be successfully passed to free() shall be
returned.

realloc
If size is 0, either a null pointer or a unique pointer that can be
successfully passed to free() shall be returned.
If size is 0 and ptr is not a null pointer, the object pointed to is freed.

g_malloc
If n_bytes is 0 it returns NULL.

g_malloc0 ()
If n_bytes is 0 it returns NULL.

g_realloc ()
n_bytes may be 0, in which case NULL will be returned and mem will be
freed unless it is NULL.

thanks
-bill
-------------- next part --------------
A non-text attachment was scrubbed...
Name: g_allocation_08_08_01.diff
Type: application/octet-stream
Size: 2203 bytes
Desc: not available
Url : http://lists.ximian.com/pipermail/mono-devel-list/attachments/20080801/a47d8bbc/attachment.obj 


More information about the Mono-devel-list mailing list