Fix memory leak and container leak