Replaced malloc/calloc calls with enif_alloc.