IB/core: fix null pointer deref and mem leak in error handling