fix memory leak, add sigint handler