diff --git a/src/openrc-shutdown/broadcast.c b/src/openrc-shutdown/broadcast.c index f21ee95c4..47af9a8d1 100644 --- a/src/openrc-shutdown/broadcast.c +++ b/src/openrc-shutdown/broadcast.c @@ -131,8 +131,8 @@ void broadcast(char *text) * These are set across the sigsetjmp call, so they can't be stored on * the stack, otherwise they might be clobbered. */ - static int fd; - static FILE *tp; + static int fd = -1; + static FILE *tp = NULL; getuidtty(&user, &tty); @@ -193,10 +193,15 @@ void broadcast(char *text) } } alarm(0); - if (fd >= 0) - close(fd); - if (tp != NULL) + if (tp != NULL) { fclose(tp); + tp = NULL; + fd = -1; /* fclose will call close for us */ + } + if (fd >= 0) { + close(fd); + fd = -1; + } free(term); } endutxent();