Fix usage of freed memory