diff options
author | 2014-05-07 15:10:33 +0000 | |
---|---|---|
committer | 2014-05-07 15:10:33 +0000 | |
commit | fb191a428d07ae6795cbacca686e42b133d99bed (patch) | |
tree | 75206de6258d63a47b546bb19e569b5cb8fa1548 /usr.bin/mandoc/mandocdb.c | |
parent | consolidate some code by using reallocarray in all cases. (diff) | |
download | wireguard-openbsd-fb191a428d07ae6795cbacca686e42b133d99bed.tar.xz wireguard-openbsd-fb191a428d07ae6795cbacca686e42b133d99bed.zip |
Fix two memory leaks in makewhatis -n:
1. As found by nigel@, names_check() requires database access.
2. Do not leak names and strings in -n mode.
Diffstat (limited to 'usr.bin/mandoc/mandocdb.c')
-rw-r--r-- | usr.bin/mandoc/mandocdb.c | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/usr.bin/mandoc/mandocdb.c b/usr.bin/mandoc/mandocdb.c index de6356673b8..a46a3e3a5ed 100644 --- a/usr.bin/mandoc/mandocdb.c +++ b/usr.bin/mandoc/mandocdb.c @@ -1,4 +1,4 @@ -/* $Id: mandocdb.c,v 1.103 2014/04/27 23:03:52 schwarze Exp $ */ +/* $Id: mandocdb.c,v 1.104 2014/05/07 15:10:33 schwarze Exp $ */ /* * Copyright (c) 2011, 2012 Kristaps Dzonsons <kristaps@bsd.lv> * Copyright (c) 2011, 2012, 2013, 2014 Ingo Schwarze <schwarze@openbsd.org> @@ -504,7 +504,7 @@ mandocdb(int argc, char *argv[]) goto out; mpages_merge(mc, mp); - if (warnings && + if (warnings && !nodb && ! (MPARSE_QUICK & mparse_options)) names_check(); dbclose(0); @@ -1988,6 +1988,18 @@ dbadd(struct mpage *mpage, struct mchars *mc) mlink = mpage->mlinks; if (nodb) { + for (key = ohash_first(&names, &slot); NULL != key; + key = ohash_next(&names, &slot)) { + if (key->rendered != key->key) + free(key->rendered); + free(key); + } + for (key = ohash_first(&strings, &slot); NULL != key; + key = ohash_next(&strings, &slot)) { + if (key->rendered != key->key) + free(key->rendered); + free(key); + } if (0 == debug) return; while (NULL != mlink) { |