Index: Src/mem.c =================================================================== RCS file: /cvsroot/zsh/zsh/Src/mem.c,v retrieving revision 1.12 diff -u -p -r1.12 mem.c --- Src/mem.c 17 Jul 2004 19:25:14 -0000 1.12 +++ Src/mem.c 4 Mar 2006 08:51:40 -0000 @@ -1241,17 +1241,6 @@ free(FREE_ARG_T p) #endif } -/* this one is for strings (and only strings, real strings, real C strings, - those that have a zero byte at the end) */ - -/**/ -mod_export void -zsfree(char *p) -{ - if (p) - zfree(p, strlen(p) + 1); -} - MALLOC_RET_T realloc(MALLOC_RET_T p, MALLOC_ARG_T size) { @@ -1463,19 +1452,34 @@ bin_mem(char *name, char **argv, Options /**/ mod_export void -zfree(void *p, UNUSED(int sz)) +zfree(void *p, int sz) { - if (p) + Heap h; + + if (!p) + return; + + queue_signals(); + for (h = heaps; h; h = h->next) + if ((char *)p >= arena(h) && (char *)p + sz < arena(h) + ARENA_SIZEOF(h)) + break; + unqueue_signals(); + + /* Do not free memory allocated in heap */ + if (!h) free(p); } /**/ +#endif + +/* this one is for strings (and only strings, real strings, real C strings, + those that have a zero byte at the end) */ + +/**/ mod_export void zsfree(char *p) { if (p) - free(p); + zfree(p, strlen(p) + 1); } - -/**/ -#endif