Add some check for malloc failure in the CAPI engine