Fixed malloc/free/realloc/calloc calls.