Index: runtime/api.h
===================================================================
--- runtime/api.h	(revision 395)
+++ runtime/api.h	(working copy)
@@ -14,14 +14,13 @@
 struct SN_env {
     symbol * p;
     int c; int a; int l; int lb; int bra; int ket;
-    int S_size; int I_size; int B_size;
     symbol * * S;
     int * I;
     symbol * B;
 };
 
 extern struct SN_env * SN_create_env(int S_size, int I_size, int B_size);
-extern void SN_close_env(struct SN_env * z);
+extern void SN_close_env(struct SN_env * z, int S_size);
 
 extern int SN_set_current(struct SN_env * z, int size, const symbol * s);
 
Index: runtime/api.c
===================================================================
--- runtime/api.c	(revision 395)
+++ runtime/api.c	(working copy)
@@ -19,43 +19,40 @@
             z->S[i] = create_s();
             if (z->S[i] == NULL) goto error;
         }
-        z->S_size = S_size;
     }
 
     if (I_size)
     {
         z->I = (int *) calloc(I_size, sizeof(int));
         if (z->I == NULL) goto error;
-        z->I_size = I_size;
     }
 
     if (B_size)
     {
         z->B = (symbol *) calloc(B_size, sizeof(symbol));
         if (z->B == NULL) goto error;
-        z->B_size = B_size;
     }
 
     return z;
 error:
-    SN_close_env(z);
+    SN_close_env(z, S_size);
     return NULL;
 }
 
-extern void SN_close_env(struct SN_env * z)
+extern void SN_close_env(struct SN_env * z, int S_size)
 {
     if (z == NULL) return;
-    if (z->S_size)
+    if (S_size)
     {
         int i;
-        for (i = 0; i < z->S_size; i++)
+        for (i = 0; i < S_size; i++)
         {
             lose_s(z->S[i]);
         }
         free(z->S);
     }
-    if (z->I_size) free(z->I);
-    if (z->B_size) free(z->B);
+    free(z->I);
+    free(z->B);
     if (z->p) lose_s(z->p);
     free(z);
 }
Index: compiler/generator.c
===================================================================
--- compiler/generator.c	(revision 395)
+++ compiler/generator.c	(working copy)
@@ -1136,7 +1136,9 @@
 
 static void generate_close(struct generator * g) {
 
-    w(g, "~Nextern void ~pclose_env(struct SN_env * z) { SN_close_env(z); }~N~N");
+    int * p = g->analyser->name_count;
+    g->I[0] = p[t_string];
+    w(g, "~Nextern void ~pclose_env(struct SN_env * z) { SN_close_env(z, ~I0); }~N~N");
 }
 
 static void generate_create_and_close_templates(struct generator * g) {

