fix memory leak and double release