change to handle malloc error by errno