From 66d1776fb85530b446dcc1f68929231849a5ad44 Mon Sep 17 00:00:00 2001 From: Rob Landley Date: Sun, 8 Jul 2018 01:16:16 -0500 Subject: Fix division by zero errors and double summary in ping. --- lib/xwrap.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'lib/xwrap.c') diff --git a/lib/xwrap.c b/lib/xwrap.c index 26383c92..d5ec9f64 100644 --- a/lib/xwrap.c +++ b/lib/xwrap.c @@ -46,12 +46,13 @@ void xexit(void) { // Call toys.xexit functions in reverse order added. while (toys.xexit) { - // This is typecasting xexit->arg to a function pointer,then calling it. - // Using the invalid signal number 0 lets the signal handlers distinguish - // an actual signal from a regular exit. - ((void (*)(int))(toys.xexit->arg))(0); + struct arg_list *al = llist_pop(&toys.xexit); - free(llist_pop(&toys.xexit)); + // typecast xexit->arg to a function pointer, then call it using invalid + // signal 0 to let signal handlers tell actual signal from regular exit. + ((void (*)(int))(al->arg))(0); + + free(al); } if (fflush(NULL) || ferror(stdout)) if (!toys.exitval) perror_msg("write"); -- cgit v1.2.3