fix memory leak
fix mem leak and empty check