sh: Fix possible memory leaks and double frees with unexpected SIGINT.