tttm

git clone https://orangeshoelaces.net/git/tttm.git

c34805014c326ebd0e89a478084a2102557a77e1

Author: Vasily Kolobkov on 05/21/2016

Committer: Vasily Kolobkov on 05/21/2016

Cleanup parser context after use

Stats

parser.c | 18 +++++++-
1 file changed, 17 insertions(+), 1 deletion(-)

Patch

diff --git a/parser.c b/parser.c
index a2c4e27..547e94f 100644
--- a/parser.c
+++ b/parser.c
@@ -163,6 +163,7 @@ static int contains(const char *, size_t, char);
 
 static void par_init(struct parctx *, struct laxsrc *,
     char *, size_t, int, union parnode *, size_t);
+static int par_free(struct parctx *);
 static int par_procure(struct parctx *, size_t, size_t);
 static int par_movewnd(struct parctx *, size_t);
 static int par_primecache(struct parctx *);
@@ -315,7 +316,7 @@ par_readln(struct laxsrc *in, char *buf, size_t buflen, int cache,
 
 	par_init(&p, in, buf, buflen, cache, pt, ptlen);
 	p_respln(&p);
-	e = par_backup(&p);
+	e = par_free(&p);
 	return e ? e : p.e;
 }
 
@@ -412,6 +413,21 @@ par_init(struct parctx *p, struct laxsrc *in, char *buf, size_t buflen,
 	p->strstor = SS_MEM;
 }
 
+int
+par_free(struct parctx *p)
+{
+	int e;
+
+	if (p->strstor == SS_CACHE && munmap(p->wnd, wndcap) == -1)
+		goto evm;
+	e = par_backup(p);
+ exit:
+	return e;
+ evm:
+	e = TE_VM;
+	goto exit;
+}
+
 /*
    Prepare window for accessing string symbols with indexes [off..off + len).
    When reading from source to fulfill the request, no less than the needed