[asterisk-dev] Re: [svn-commits] rizzo: trunk r48389 -
/trunk/main/manager.c
Russell Bryant
russell at digium.com
Tue Dec 12 10:39:43 MST 2006
svn-commits at lists.digium.com wrote:
> Author: rizzo
> Date: Mon Dec 11 12:11:58 2006
> New Revision: 48389
>
> URL: http://svn.digium.com/view/asterisk?view=rev&rev=48389
> Log:
> make sure the argument to ast_malloc() is > 0.
>
> Long explaination:
>
> The behaviour of the underlying malloc(0) differs depending on the
> operating system. Some return NULL (SysV behaviour); some still
> allocate a small chunk of memory and return a valid pointer (e.g.
> traditional BSD); some (e.g. FreeBSD 6.x) return a non-null pointer
> that causes a memory fault if used, even just for reading.
>
> Given the above variety, better never call malloc(0).
Autoconf actually has a macro to check for this behavior. However, I'm thinking
that maybe the safest, and least obfuscated thing to do is to just modify the
ast_*() memory allocation wrappers to check for an argument of zero and allocate
a single byte in that case.
For reference ...
[Macro] AC FUNC MALLOC
If the malloc function is compatible with the gnu C library malloc (i.e.,
‘malloc (0)’ returns a valid pointer), define HAVE_MALLOC to 1. Otherwise define
HAVE_MALLOC to 0, ask for an AC_LIBOBJ replacement for ‘malloc’, and define
malloc to rpl_malloc so that the native malloc is not used in the main project.
Typically, the replacement file ‘malloc.c’ should look like (note the ‘#undef
malloc’):
#if HAVE_CONFIG_H
# include <config.h>
#endif
#undef malloc
#include <sys/types.h>
void *malloc ();
/* Allocate an N-byte block of memory from the heap.
If N is zero, allocate a 1-byte block. */
void *
rpl_malloc (size_t n)
{
if (n == 0)
n = 1;
return malloc (n);
}
--
Russell Bryant
Software Engineer
Digium, Inc.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: russell.vcf
Type: text/x-vcard
Size: 278 bytes
Desc: not available
Url : http://lists.digium.com/pipermail/asterisk-dev/attachments/20061212/fc785bf8/russell.vcf
More information about the asterisk-dev
mailing list