Added <stdlib.h> to the includes to get prototypes for malloc() and realloc(). This was manifesting as a problem on OS/X because the pointer returned was being truncated to 32 bits.