Fixed incomplete cleanup which caused a double free.