Fix freeing of unallocated memory.