Fix possible memory leak in error situation