Fixed a memory freeing bug.