removed memory leaks on failure