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

Zoltan Varga vargaz at gmail.com
Fri Aug 1 16:55:24 EDT 2008


Hi,

  Approved.

       Zoltan

2008/8/1 Bill Holmes <billholmes54 at gmail.com>:
> 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
>
> _______________________________________________
> Mono-devel-list mailing list
> Mono-devel-list at lists.ximian.com
> http://lists.ximian.com/mailman/listinfo/mono-devel-list
>
>


More information about the Mono-devel-list mailing list