caif: add error handling for allocation