diff --git a/asm/preproc.c b/asm/preproc.c
index cb1669da..49987678 100644
--- a/asm/preproc.c
+++ b/asm/preproc.c
@@ -1841,7 +1841,7 @@ static Token *new_Token_free(Token * next, enum token_type type,
 
     if (txtlen <= INLINE_TEXT) {
         memcpy(t->text.a, text, txtlen);
-        free(text);
+        nasm_free(text);
     } else {
         t->text.p.ptr = text;
     }
@@ -7288,9 +7288,11 @@ static Token *pp_tokline(void)
             if (mmac) {
                 const Token *t;
                 list_for_each(t, tline) {
-                    if (t->type == TOKEN_PREPROC_ID &&
+                    if (t->type == TOKEN_MMACRO_PARAM &&
                         !memcmp(t->text.a, "%00", 4))
                         mmac->capture_label = true;
+                    if (0) printf("t->type=%u t->text.a=%s TOKEN_PREPROC_ID=%u\n",
+                      t->type, t->text.a, TOKEN_PREPROC_ID);
                 }
             }
         } else if (istk->conds && !emitting(istk->conds->state)) {
diff --git a/nasmlib/alloc.c b/nasmlib/alloc.c
index e25e0e0a..b20d43e7 100644
--- a/nasmlib/alloc.c
+++ b/nasmlib/alloc.c
@@ -41,6 +41,17 @@
 #include "alloc.h"
 
 size_t _nasm_last_string_size;
+static FILE * logfile = NULL;
+static size_t logamount = 0;
+static size_t logtotal = 0;
+
+void openlogfile(void);
+void openlogfile(void) {
+	if (logfile) return;
+	logfile = fopen("nasmaloc.log", "wb");
+	if (!logfile) nasm_critical("opening log file failed!");
+	return;
+}
 
 fatal_func nasm_alloc_failed(void)
 {
@@ -50,6 +61,8 @@ fatal_func nasm_alloc_failed(void)
 void *nasm_malloc(size_t size)
 {
     void *p;
+	openlogfile();
+	size += 8;
 
 again:
     p = malloc(size);
@@ -59,14 +72,27 @@ again:
             size = 1;
             goto again;
         }
+	fprintf(logfile, "[%16lu] (%16lu) unable to allocate %lu bytes\n",
+		logamount, logtotal, size);
+	fflush(logfile);
         nasm_alloc_failed();
     }
-    return p;
+	logamount += size;
+	logtotal += size;
+	*(size_t *)p = size;
+	fprintf(logfile, "[%16lu] (%16lu) allocated %lu bytes at %p\n",
+		logamount, logtotal, size, p);
+	fflush(logfile);
+    return (void *)((unsigned char *)p + 8);
 }
 
 void *nasm_calloc(size_t nelem, size_t size)
 {
     void *p;
+	openlogfile();
+	size = size * nelem;
+	nelem = 1;
+	size += 8;
 
 again:
     p = calloc(nelem, size);
@@ -76,10 +102,18 @@ again:
             nelem = size = 1;
             goto again;
         }
+	fprintf(logfile, "[%16lu] (%16lu) unable to allocate %lu bytes\n",
+		logamount, logtotal, size);
+	fflush(logfile);
         nasm_alloc_failed();
     }
-
-    return p;
+	logamount += size;
+	logtotal += size;
+	*(size_t *)p = size;
+	fprintf(logfile, "[%16lu] (%16lu) allocated %lu bytes at %p\n",
+		logamount, logtotal, size, p);
+	fflush(logfile);
+    return (void *)((unsigned char *)p + 8);
 }
 
 void *nasm_zalloc(size_t size)
@@ -96,16 +130,48 @@ void *nasm_zalloc(size_t size)
  */
 void *nasm_realloc(void *q, size_t size)
 {
+	size_t originalsize = 0;
+	void * originalpointer;
+	openlogfile();
+	size += 8;
+	if (q) {
+		q = (void *)((unsigned char *)q - 8);
+		originalsize = *(size_t *)q;
+	}
+	originalpointer = q;
     if (unlikely(!size))
         size = 1;
     q = q ? realloc(q, size) : malloc(size);
-    return validate_ptr(q);
+if (!q) {
+	fprintf(logfile, "[%16lu] (%16lu) unable to allocate %lu bytes\n",
+		logamount, logtotal, size);
+	fflush(logfile);
+}
+    q = validate_ptr(q);
+	logamount -= originalsize;
+	logamount += size;
+	logtotal += size;
+	*(size_t *)q = size;
+	fprintf(logfile, "[%16lu] (%16lu) re-allocated from %lu bytes at %p to %lu bytes at %p\n",
+		logamount, logtotal, originalsize, originalpointer, size, q);
+	fflush(logfile);
+    return (void *)((unsigned char *)q + 8);
 }
 
 void nasm_free(void *q)
 {
+	size_t size;
+	openlogfile();
     if (q)
+	{
+	q = (void *)((unsigned char *)q - 8);
+	size = *(size_t *)q;
+	logamount -= size;
+	fprintf(logfile, "[%16lu] (%16lu) freed from %lu bytes at %p\n",
+		logamount, logtotal, size, q);
+	fflush(logfile);
         free(q);
+	}
 }
 
 char *nasm_strdup(const char *s)
diff --git a/version b/version
deleted file mode 100644
index 015a89ee..00000000
--- a/version
+++ /dev/null
@@ -1 +0,0 @@
-2.16rc0
