diff --git a/modules/src/malloc/log.h b/modules/src/malloc/log.h index d1d8929a2..a15c7b523 100644 --- a/modules/src/malloc/log.h +++ b/modules/src/malloc/log.h @@ -10,8 +10,20 @@ public link_free_chunk(), unlink_free_chunk(); public mallink *first_present(), *search_free_list(); +#ifdef STORE +#define in_store(ml) ((size_type)_log_prev_of(ml) & 01) +#define set_store(ml, e) \ + (_log_prev_of(ml) = (mallink *) \ + ((e) ? (size_type) _log_prev_of(ml) | 01 : \ + (size_type) _log_prev_of(ml) & ~01)) +#define log_prev_of(ml) (mallink *)((size_type)_log_prev_of(ml) & ~01) +#define set_log_prev(ml,e) \ + (_log_prev_of(ml) = (mallink *)((char *)e + in_store(ml))) +#else #define set_log_prev(ml,e) (_log_prev_of(ml) = (e)) #define log_prev_of(ml) (mallink *) (_log_prev_of(ml)) +#endif #define set_log_next(ml,e) (_log_next_of(ml) = (e)) #define log_next_of(ml) (mallink *) (_log_next_of(ml)) + diff --git a/modules/src/malloc/mal.c b/modules/src/malloc/mal.c index 3c602d596..67b5356ca 100644 --- a/modules/src/malloc/mal.c +++ b/modules/src/malloc/mal.c @@ -26,11 +26,11 @@ #define ILL_BREAK (char *)(-1) /* funny failure value */ #endif extern char *SBRK(); +privatedata char *freed; #ifdef STORE #define MAX_STORE 32 private do_free(), Xfree(), sell_out(); privatedata mallink *store[MAX_STORE]; -privatedata char *freed; #endif STORE char * @@ -49,6 +49,7 @@ malloc(n) if (ml = *stp) { *stp = log_next_of(ml); + set_store(ml, 0); check_mallinks("malloc fast exit"); return block_of_mallink(ml); } @@ -152,7 +153,7 @@ Xfree() #ifdef STORE freed = 0; - if (free_of(ml)) + if (free_of(ml) || in_store(ml)) return; /* user frees free block */ if (size_of(ml) <= MAX_STORE*MIN_SIZE) { /* return to store */ @@ -160,6 +161,7 @@ Xfree() set_log_next(ml, *stp); *stp = ml; + set_store(ml, 1); check_mallinks("free fast exit"); } else { @@ -283,6 +285,7 @@ sell_out() { while (ml) { *stp = log_next_of(ml); + set_store(ml, 0); do_free(ml); ml = *stp; }