From: tb Date: Thu, 8 Feb 2018 01:36:38 +0000 (+0000) Subject: Invalidate the tag_files.tfd after fclose(3)ing the stram associated with X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=3c22eb7bb64b4ebb3da79beaa4c00a535429462a;p=openbsd Invalidate the tag_files.tfd after fclose(3)ing the stram associated with it. In main assert that the tfd was actually invalidated. This avoids closing an invalid fd. ok deraadt on earlier version, tweak & ok schwarze --- diff --git a/usr.bin/mandoc/main.c b/usr.bin/mandoc/main.c index 2c2377670fe..e7b875aec04 100644 --- a/usr.bin/mandoc/main.c +++ b/usr.bin/mandoc/main.c @@ -1,4 +1,4 @@ -/* $OpenBSD: main.c,v 1.205 2017/08/21 15:41:26 schwarze Exp $ */ +/* $OpenBSD: main.c,v 1.206 2018/02/08 01:36:38 tb Exp $ */ /* * Copyright (c) 2008-2012 Kristaps Dzonsons * Copyright (c) 2010-2012, 2014-2017 Ingo Schwarze @@ -1152,7 +1152,7 @@ spawn_pager(struct tag_files *tag_files) if (dup2(tag_files->ofd, STDOUT_FILENO) == -1) err((int)MANDOCLEVEL_SYSERR, "pager stdout"); close(tag_files->ofd); - close(tag_files->tfd); + assert(tag_files->tfd == -1); /* Do not start the pager before controlling the terminal. */ diff --git a/usr.bin/mandoc/tag.c b/usr.bin/mandoc/tag.c index bcf1a55fdd6..9c9674be9d7 100644 --- a/usr.bin/mandoc/tag.c +++ b/usr.bin/mandoc/tag.c @@ -1,4 +1,4 @@ -/* $OpenBSD: tag.c,v 1.18 2017/02/09 17:19:07 schwarze Exp $ */ +/* $OpenBSD: tag.c,v 1.19 2018/02/08 01:36:38 tb Exp $ */ /* * Copyright (c) 2015, 2016 Ingo Schwarze * @@ -211,6 +211,9 @@ tag_write(void) ohash_delete(&tag_data); if (stream != NULL) fclose(stream); + else + close(tag_files.tfd); + tag_files.tfd = -1; } void