aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/mandocdb.c
diff options
context:
space:
mode:
authorIngo Schwarze <schwarze@openbsd.org>2014-05-07 15:10:36 +0000
committerIngo Schwarze <schwarze@openbsd.org>2014-05-07 15:10:36 +0000
commitad9934ce8bce7df653e1eec762a8e13b6ca42b55 (patch)
tree98bcc766860433bef8913981f87f4289842064d6 /mandocdb.c
parente9fa61ef565b232a81f24582132198563730fbcc (diff)
downloadmandoc-ad9934ce8bce7df653e1eec762a8e13b6ca42b55.tar.gz
mandoc-ad9934ce8bce7df653e1eec762a8e13b6ca42b55.tar.zst
mandoc-ad9934ce8bce7df653e1eec762a8e13b6ca42b55.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 'mandocdb.c')
-rw-r--r--mandocdb.c16
1 files changed, 14 insertions, 2 deletions
diff --git a/mandocdb.c b/mandocdb.c
index f9e04602..85f0cca0 100644
--- a/mandocdb.c
+++ b/mandocdb.c
@@ -1,4 +1,4 @@
-/* $Id: mandocdb.c,v 1.146 2014/04/27 23:08:56 schwarze Exp $ */
+/* $Id: mandocdb.c,v 1.147 2014/05/07 15:10:36 schwarze Exp $ */
/*
* Copyright (c) 2011, 2012 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2011, 2012, 2013, 2014 Ingo Schwarze <schwarze@openbsd.org>
@@ -512,7 +512,7 @@ main(int argc, char *argv[])
goto out;
mpages_merge(mc, mp);
- if (warnings &&
+ if (warnings && !nodb &&
! (MPARSE_QUICK & mparse_options))
names_check();
dbclose(0);
@@ -1996,6 +1996,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) {