fixed possible dangling pointers in *Free functions