Fix possible memory leak
Ignore SIGPIPE and use sig_atomic_t instead of int in the signal handler