...
Code Block | ||
---|---|---|
| ||
#include <signal.h>
char *foo;
void int_handler() {
free(foo);
_Exit(0);
/* _Exit() causes immediate program termination, and is
async-safe, whereas exit() calls cleanup routines first,
and is not async-safe. */
}
int main(void) {
foo = malloc(15);
if(foo == NULL) {
/* handle error condition */
return 0;
}
signal(SIGINT, int_handler);
strcpy(foo, "Hello World.");
puts(foo);
free(foo);
return 0;
}
|
...