fix memory free bug