From 8055da743735f19695a9b0bf32b7f10875d7ca8b Mon Sep 17 00:00:00 2001 From: schwarze Date: Mon, 4 Oct 2021 14:18:42 +0000 Subject: [PATCH] store the operating system name obtained from uname(3) in the adequate struct together with similar state date rather than in a function-scope static variable, such that it can be free(3)d in roff_man_free(); no functional change --- usr.bin/mandoc/mdoc_validate.c | 13 ++++++------- usr.bin/mandoc/roff.c | 5 +++-- usr.bin/mandoc/roff_int.h | 3 ++- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/usr.bin/mandoc/mdoc_validate.c b/usr.bin/mandoc/mdoc_validate.c index 1e1669adb6e..9e681af4b50 100644 --- a/usr.bin/mandoc/mdoc_validate.c +++ b/usr.bin/mandoc/mdoc_validate.c @@ -1,6 +1,6 @@ -/* $OpenBSD: mdoc_validate.c,v 1.304 2021/07/18 11:40:58 schwarze Exp $ */ +/* $OpenBSD: mdoc_validate.c,v 1.305 2021/10/04 14:18:42 schwarze Exp $ */ /* - * Copyright (c) 2010-2020 Ingo Schwarze + * Copyright (c) 2010-2021 Ingo Schwarze * Copyright (c) 2008-2012 Kristaps Dzonsons * Copyright (c) 2010 Joerg Sonnenberger * @@ -2857,7 +2857,6 @@ post_os(POST_ARGS) { #ifndef OSNAME struct utsname utsname; - static char *defbuf; #endif struct roff_node *n; @@ -2894,15 +2893,15 @@ post_os(POST_ARGS) #ifdef OSNAME mdoc->meta.os = mandoc_strdup(OSNAME); #else /*!OSNAME */ - if (defbuf == NULL) { + if (mdoc->os_r == NULL) { if (uname(&utsname) == -1) { mandoc_msg(MANDOCERR_OS_UNAME, n->line, n->pos, "Os"); - defbuf = mandoc_strdup("UNKNOWN"); + mdoc->os_r = mandoc_strdup("UNKNOWN"); } else - mandoc_asprintf(&defbuf, "%s %s", + mandoc_asprintf(&mdoc->os_r, "%s %s", utsname.sysname, utsname.release); } - mdoc->meta.os = mandoc_strdup(defbuf); + mdoc->meta.os = mandoc_strdup(mdoc->os_r); #endif /*!OSNAME*/ out: diff --git a/usr.bin/mandoc/roff.c b/usr.bin/mandoc/roff.c index 1910061eca0..94a4e7e84c7 100644 --- a/usr.bin/mandoc/roff.c +++ b/usr.bin/mandoc/roff.c @@ -1,6 +1,6 @@ -/* $OpenBSD: roff.c,v 1.251 2021/10/04 10:11:54 schwarze Exp $ */ +/* $OpenBSD: roff.c,v 1.252 2021/10/04 14:18:42 schwarze Exp $ */ /* - * Copyright (c) 2010-2015, 2017-2020 Ingo Schwarze + * Copyright (c) 2010-2015, 2017-2021 Ingo Schwarze * Copyright (c) 2008-2012, 2014 Kristaps Dzonsons * * Permission to use, copy, modify, and distribute this software for any @@ -859,6 +859,7 @@ void roff_man_free(struct roff_man *man) { roff_man_free1(man); + free(man->os_r); free(man); } diff --git a/usr.bin/mandoc/roff_int.h b/usr.bin/mandoc/roff_int.h index 779f50f7e6a..c2a9246076f 100644 --- a/usr.bin/mandoc/roff_int.h +++ b/usr.bin/mandoc/roff_int.h @@ -1,4 +1,4 @@ -/* $OpenBSD: roff_int.h,v 1.17 2020/04/24 11:58:02 schwarze Exp $ */ +/* $OpenBSD: roff_int.h,v 1.18 2021/10/04 14:18:42 schwarze Exp $ */ /* * Copyright (c) 2013-2015, 2017-2020 Ingo Schwarze * Copyright (c) 2009, 2010, 2011 Kristaps Dzonsons @@ -35,6 +35,7 @@ struct roff_man { struct ohash *mdocmac; /* Mdoc macro lookup table. */ struct ohash *manmac; /* Man macro lookup table. */ const char *os_s; /* Default operating system. */ + char *os_r; /* Operating system name at run time. */ struct roff_node *last; /* The last node parsed. */ struct roff_node *last_es; /* The most recent Es node. */ int quick; /* Abort parse early. */ -- 2.20.1