source@mandoc.bsd.lv
 help / color / mirror / Atom feed
* mandoc: In man(1) mode, properly clean up the resn[] result array after
@ 2021-10-04 20:24 schwarze
  0 siblings, 0 replies; only message in thread
From: schwarze @ 2021-10-04 20:24 UTC (permalink / raw)
  To: source

Log Message:
-----------
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.

Modified Files:
--------------
    mandoc:
        main.c

Revision Data
-------------
Index: main.c
===================================================================
RCS file: /home/cvs/mandoc/mandoc/main.c,v
retrieving revision 1.358
retrieving revision 1.359
diff -Lmain.c -Lmain.c -u -p -r1.358 -r1.359
--- main.c
+++ 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. */
--
 To unsubscribe send an email to source+unsubscribe@mandoc.bsd.lv


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2021-10-04 20:24 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-04 20:24 mandoc: In man(1) mode, properly clean up the resn[] result array after schwarze

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).