From: schwarze Date: Mon, 4 Oct 2021 20:24:00 +0000 (+0000) Subject: In man(1) mode, properly clean up the resn[] result array X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=0883e5d9c2df7753e2e24a49e1643f365d5c7d25;p=openbsd In man(1) mode, properly clean up the resn[] result array after processing each name given on the command line. Failure to do so resulted in a memory leak of about 50 kilobytes per name given on the command line. Since man(1) uses a few Megabytes of memory anyway and people rarely give hundreds of names on the command line, this leak did not cause practical problems, but cleaning up properly is better in any case. --- diff --git a/usr.bin/mandoc/main.c b/usr.bin/mandoc/main.c index a6c7341b6d3..20ff8a63593 100644 --- a/usr.bin/mandoc/main.c +++ b/usr.bin/mandoc/main.c @@ -1,4 +1,4 @@ -/* $OpenBSD: main.c,v 1.260 2021/09/04 22:37:26 schwarze Exp $ */ +/* $OpenBSD: main.c,v 1.261 2021/10/04 20:24:00 schwarze Exp $ */ /* * Copyright (c) 2010-2012, 2014-2021 Ingo Schwarze * Copyright (c) 2008-2012 Kristaps Dzonsons @@ -494,6 +494,9 @@ main(int argc, char *argv[]) memcpy(res + ressz, resn, sizeof(*resn) * resnsz); ressz += resnsz; + free(resn); + resn = NULL; + resnsz = 0; continue; } @@ -532,6 +535,10 @@ main(int argc, char *argv[]) res = mandoc_reallocarray(res, ressz + 1, sizeof(*res)); memcpy(res + ressz++, resn + ib, sizeof(*resn)); + memset(resn + ib, 0, sizeof(*resn)); + mansearch_free(resn, resnsz); + resn = NULL; + resnsz = 0; } /* apropos(1), whatis(1): Process the full search expression. */