mac don't have malloc.h, and fix a bug