Fixed null pointer deref during error handling