aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorKristaps Dzonsons <kristaps@bsd.lv>2009-03-17 13:35:46 +0000
committerKristaps Dzonsons <kristaps@bsd.lv>2009-03-17 13:35:46 +0000
commit49c322efa56dea298f42cc8bddd6629093d45975 (patch)
tree72450046c6e5f43699f78eb8bee1512a73a1b551
parent20f79639b5b34e231e85135e96d7f2312690ba8e (diff)
downloadmandoc-49c322efa56dea298f42cc8bddd6629093d45975.tar.gz
mandoc-49c322efa56dea298f42cc8bddd6629093d45975.tar.zst
mandoc-49c322efa56dea298f42cc8bddd6629093d45975.zip
Clean up ASCII table's memory.
-rw-r--r--ascii.c47
-rw-r--r--mdocterm.c3
-rw-r--r--term.h3
3 files changed, 41 insertions, 12 deletions
diff --git a/ascii.c b/ascii.c
index 80523e5f..0ff1d9a9 100644
--- a/ascii.c
+++ b/ascii.c
@@ -1,4 +1,4 @@
-/* $Id: ascii.c,v 1.1 2009/03/16 22:19:19 kristaps Exp $ */
+/* $Id: ascii.c,v 1.2 2009/03/17 13:35:46 kristaps Exp $ */
/*
* Copyright (c) 2009 Kristaps Dzonsons <kristaps@openbsd.org>
*
@@ -33,16 +33,16 @@
*/
struct line {
- const char *code;
- const char *out;
+ const char *code;
+ const char *out;
/* 32- and 64-bit alignment safe. */
- size_t codesz;
- size_t outsz;
+ size_t codesz;
+ size_t outsz;
};
struct linep {
const struct line *line;
- struct linep *next;
+ struct linep *next;
};
#define LINE(w, x, y, z) \
@@ -51,14 +51,33 @@ static const struct line lines[] = {
#include "ascii.in"
};
+struct asciitab {
+ struct linep *lines;
+ void **htab;
+};
+
-static inline int match(const struct line *,
+static inline int match(const struct line *,
const char *, size_t);
+void
+asciifree(void *arg)
+{
+ struct asciitab *tab;
+
+ tab = (struct asciitab *)arg;
+
+ free(tab->lines);
+ free(tab->htab);
+ free(tab);
+}
+
+
void *
ascii2htab(void)
{
+ struct asciitab *tab;
void **htab;
struct linep *pp, *p;
int i, len, hash;
@@ -70,6 +89,9 @@ ascii2htab(void)
* (they're in-line re-ordered during lookup).
*/
+ if (NULL == (tab = malloc(sizeof(struct asciitab))))
+ err(1, "malloc");
+
assert(0 == sizeof(lines) % sizeof(struct line));
len = sizeof(lines) / sizeof(struct line);
@@ -102,18 +124,23 @@ ascii2htab(void)
pp->next = &p[i];
}
- return((void *)htab);
+ tab->htab = htab;
+ tab->lines = p;
+
+ return(tab);
}
const char *
-a2ascii(void *htabp, const char *p, size_t sz, size_t *rsz)
+a2ascii(void *arg, const char *p, size_t sz, size_t *rsz)
{
+ struct asciitab *tab;
struct linep *pp, *prev;
void **htab;
int hash;
- htab = (void **)htabp;
+ tab = (struct asciitab *)arg;
+ htab = tab->htab;
assert(p);
assert(sz > 0);
diff --git a/mdocterm.c b/mdocterm.c
index 4bcea5e4..9742dbef 100644
--- a/mdocterm.c
+++ b/mdocterm.c
@@ -1,4 +1,4 @@
-/* $Id: mdocterm.c,v 1.47 2009/03/16 23:37:28 kristaps Exp $ */
+/* $Id: mdocterm.c,v 1.48 2009/03/17 13:35:46 kristaps Exp $ */
/*
* Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@openbsd.org>
*
@@ -113,6 +113,7 @@ main(int argc, char *argv[])
footer(&termp, mdoc_meta(mdoc));
free(termp.buf);
+ asciifree(termp.symtab);
mmain_exit(p, 0);
/* NOTREACHED */
diff --git a/term.h b/term.h
index ff1c1173..206dada2 100644
--- a/term.h
+++ b/term.h
@@ -1,4 +1,4 @@
-/* $Id: term.h,v 1.25 2009/03/16 22:19:19 kristaps Exp $ */
+/* $Id: term.h,v 1.26 2009/03/17 13:35:46 kristaps Exp $ */
/*
* Copyright (c) 2008 Kristaps Dzonsons <kristaps@kth.se>
*
@@ -81,6 +81,7 @@ struct termact {
void *ascii2htab(void);
const char *a2ascii(void *, const char *, size_t, size_t *);
+void asciifree(void *);
void newln(struct termp *);
void vspace(struct termp *);