Fixed a bug about double freeing.