revert unintended change and reimplement replacing malloc/memset with calloc and checking return
revert changes that shouldn't be in this branch