I just saw this code:
artist = (char *) malloc(0);
...and I was wondering why would one do this?
In Windows:
void *p = malloc(0);
will allocate a zero-length buffer on the local heap. The pointer returned is a valid heap pointer.malloc
ultimately calls HeapAlloc
using the default C runtime heap which then calls RtlAllocateHeap
, etc.free(p);
uses HeapFree
to free the 0-length buffer on the heap. Not freeing it would result in a memory leak.