void * emalloc(size)
size_t size;
{
void * ptr;
/*
* Just for our personal safety, we increase the
* size by one
*/
if((int)size < 0)
{
fprintf(stderr, "[%d] Won't allocate a pointer of size %ld !\n", getpid(), size);
exit(1);
}
size++;
/*
* If no memory can be allocated, then wait a little.
* It's very likely that another nessusd child will free
* the size of memory we need. So we make 10 attempts,
* and if nothing happens, then we exit
*/
ptr = malloc(size);
if(!ptr){
int i;
for(i=0; (i<5) && ptr == NULL ;i++)
{
waitpid(0, NULL, WNOHANG);
usleep(5000);
ptr = malloc(size);
}
if( ptr == NULL )
{
fprintf(stderr, "[%d] Could not allocate a pointer of size %ld !\n", getpid(), size);
exit(1);
}
}
bzero(ptr, size);
return(ptr);
}