backported malloc fixes from 256boss, plus the addition of calloc and