core[xavp]: manage error cases properly. We don't want memory leaks.