add malloc error handling.