* mdocml: Avoid leaking index records: Before allocating a record for a
@ 2011-12-10 22:01 schwarze
0 siblings, 0 replies; only message in thread
From: schwarze @ 2011-12-10 22:01 UTC (permalink / raw)
To: source
Log Message:
-----------
Avoid leaking index records:
Before allocating a record for a file,
first make sure we actually want to use the file.
Modified Files:
--------------
mdocml:
mandocdb.c
Revision Data
-------------
Index: mandocdb.c
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/mandocdb.c,v
retrieving revision 1.32
retrieving revision 1.33
diff -Lmandocdb.c -Lmandocdb.c -u -p -r1.32 -r1.33
--- mandocdb.c
+++ mandocdb.c
@@ -528,29 +528,15 @@ index_merge(const struct of *of, struct
fn = of->fname;
/*
- * Reclaim an empty index record, if available.
+ * Try interpreting the file as mdoc(7) or man(7)
+ * source code, unless it is already known to be
+ * formatted. Fall back to formatted mode.
*/
- if (reccur > 0) {
- --reccur;
- rec = recs[(int)reccur];
- } else if (maxrec > 0) {
- rec = maxrec;
- maxrec = 0;
- } else
- rec++;
-
mparse_reset(mp);
- hash_reset(&hash);
mdoc = NULL;
man = NULL;
- /*
- * Try interpreting the file as mdoc(7) or man(7)
- * source code, unless it is already known to be
- * formatted. Fall back to formatted mode.
- */
-
if ((MANDOC_SRC & of->src_form ||
! (MANDOC_FORM & of->src_form)) &&
MANDOCLEVEL_FATAL > mparse_readfd(mp, -1, fn))
@@ -625,8 +611,12 @@ index_merge(const struct of *of, struct
sv = dbuf->len;
- /* Fix the record number in the btree value. */
+ /*
+ * Collect keyword/mask pairs.
+ * Each pair will become a new btree node.
+ */
+ hash_reset(&hash);
if (mdoc)
pmdoc_node(hash, buf, dbuf,
mdoc_node(mdoc), mdoc_meta(mdoc));
@@ -636,11 +626,25 @@ index_merge(const struct of *of, struct
pformatted(hash, buf, dbuf, of);
/*
- * Copy from the in-memory hashtable of pending keywords
- * into the database.
+ * Reclaim an empty index record, if available.
+ * Use its record number for all new btree nodes.
*/
+ if (reccur > 0) {
+ --reccur;
+ rec = recs[(int)reccur];
+ } else if (maxrec > 0) {
+ rec = maxrec;
+ maxrec = 0;
+ } else
+ rec++;
vbuf.rec = htobe32(rec);
+
+ /*
+ * Copy from the in-memory hashtable of pending
+ * keyword/mask pairs into the database.
+ */
+
seq = R_FIRST;
while (0 == (ch = (*hash->seq)(hash, &key, &val, seq))) {
seq = R_NEXT;
--
To unsubscribe send an email to source+unsubscribe@mdocml.bsd.lv
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2011-12-10 22:01 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-12-10 22:01 mdocml: Avoid leaking index records: Before allocating a record for a 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).