--- stack/stack.c 2002/02/14 19:20:28 1.81 +++ stack/stack.c 2002/02/14 22:44:49 1.83 @@ -8,6 +8,8 @@ #include /* strcmp, strcpy, strlen, strcat, strdup */ #include +/* mtrace, muntrace */ +#include #define HASHTBLSIZE 2048 @@ -103,12 +105,15 @@ break; case integer: case func: + break; case symb: + free(((symbol*)(val->content.ptr))->id); + if(((symbol*)(val->content.ptr))->val!=NULL) + free_val(((symbol*)(val->content.ptr))->val); + free(val->content.ptr); break; } - if(val->id!=NULL) - free(val->id); - free(val); /* Free the actual list value */ + free(val); /* Free the actual value structure */ } } @@ -174,8 +179,7 @@ new_value->content.val= in_val; new_value->type= integer; - new_value->refcount= 1; - new_value->id= NULL; + new_value->refcount= 0; push_val(env, new_value); } @@ -188,8 +192,7 @@ new_value->content.ptr= malloc(strlen(in_string)+1); strcpy(new_value->content.ptr, in_string); new_value->type= string; - new_value->refcount= 1; - new_value->id= NULL; + new_value->refcount= 0; push_val(env, new_value); } @@ -608,7 +611,7 @@ pack= malloc(sizeof(value)); pack->type= list; pack->content.ptr= temp; - pack->refcount= 1; + pack->refcount= 0; push_val(env, pack); rev(env); @@ -737,6 +740,7 @@ extern void clear(environment *); void forget_sym(symbol **); +extern void words(environment *); /* Quit stack. */ extern void quit(environment *env) @@ -744,6 +748,9 @@ long i; clear(env); + + words(env); + if (env->err) return; for(i= 0; isymbols[i]!= NULL) { @@ -751,6 +758,14 @@ } env->symbols[i]= NULL; } + + words(env); + + if(env->free_string!=NULL) + free(env->free_string); + + muntrace(); + exit(EXIT_SUCCESS); } @@ -825,6 +840,8 @@ { environment myenv; + mtrace(); + init_env(&myenv); while(1) { @@ -1200,7 +1217,7 @@ temp_val= malloc(sizeof(value)); temp_val->content.ptr= env->head; - temp_val->refcount= 1; + temp_val->refcount= 0; temp_val->type= list; env->head= temp_head; push_val(env, temp_val); @@ -1226,7 +1243,7 @@ int itemp, readlength= -1; static int depth= 0; - char *rest, *match; + char *match; size_t inlength; if(env->in_string==NULL) { @@ -1243,7 +1260,6 @@ inlength= strlen(env->in_string)+1; match= malloc(inlength); - rest= malloc(inlength); if(sscanf(env->in_string, blankform, &readlength)!=EOF && readlength != -1) { @@ -1271,12 +1287,13 @@ } else { free(env->free_string); env->in_string = env->free_string = NULL; - free(match); } if ( env->in_string != NULL) { env->in_string += readlength; } + free(match); + if(depth) return read(env); }