From 6fbe38912d7f8b9ee6a226f22eaacc688f92d264 Mon Sep 17 00:00:00 2001 From: Ingo Schwarze Date: Mon, 4 Oct 2021 20:24:06 +0000 Subject: 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. --- main.c | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'main.c') diff --git a/main.c b/main.c index 71df95fb..877b8d01 100644 --- a/main.c +++ b/main.c @@ -516,6 +516,9 @@ main(int argc, char *argv[]) memcpy(res + ressz, resn, sizeof(*resn) * resnsz); ressz += resnsz; + free(resn); + resn = NULL; + resnsz = 0; continue; } @@ -554,6 +557,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. */ -- cgit