[sheepdog] Question about memory allocation functions in lib/util.c

Hitoshi Mitake h.mitake at gmail.com
Mon Oct 1 15:46:34 CEST 2012


Hi,

I have a question about the memory allocation functions in lib/util.c
of sheepdog.

It seems that xmalloc(), xcalloc(), and xrealloc() try to allocate 1
byte area if first allocation fails
and the size of requested area is 0.

e.g. this is the head part of of xmalloc()
void *xmalloc(size_t size)
{
	void *ret = malloc(size);
	if (!ret && !size)
		ret = malloc(1);
...

I couldn't understand the intention of this implementation.
What is the intention of these behaviours?

Thanks,
Hitoshi



More information about the sheepdog mailing list