From b1ee8fe36bd633663557fcfced3aafe39a44e312 Mon Sep 17 00:00:00 2001 From: ceriel Date: Mon, 17 Jul 1989 15:13:09 +0000 Subject: [PATCH] fixed a problem with the store: we sometimes lost some memory --- modules/src/malloc/impl.h | 4 ++++ modules/src/malloc/mal.c | 14 ++++++++++++++ modules/src/malloc/phys.c | 2 ++ 3 files changed, 20 insertions(+) diff --git a/modules/src/malloc/impl.h b/modules/src/malloc/impl.h index ed2d2766f..3b92fe8b2 100644 --- a/modules/src/malloc/impl.h +++ b/modules/src/malloc/impl.h @@ -56,6 +56,10 @@ typedef union _inf mallink; #define checksum_of(ml) (_checksum_of(ml)) #endif CHECK +#define new_mallink(ml) ( _log_prev_of(ml) = 0, \ + _log_next_of(ml) = 0, \ + _phys_prev_of(ml) = 0, \ + _this_size_of(ml) = 0 ) #define block_of_mallink(ml) ((char *)ml) #define mallink_of_block(addr) ((mallink *)addr) diff --git a/modules/src/malloc/mal.c b/modules/src/malloc/mal.c index b7a72ac0f..e3309102d 100644 --- a/modules/src/malloc/mal.c +++ b/modules/src/malloc/mal.c @@ -232,6 +232,20 @@ realloc(addr, n) } ml = mallink_of_block(addr); if (n < MIN_SIZE) n = align(MIN_SIZE); else n = align(n); +#ifdef STORE + if (in_store(ml)) { + register mallink *stp = store[(size_of(ml) >> LOG_MIN_SIZE) - 1]; + mallink *stp1 = 0; + while (ml != stp) { + stp1 = stp; + stp = log_next_of(stp); + } + stp = log_next_of(stp); + if (! stp1) store[(size_of(ml) >> LOG_MIN_SIZE) - 1] = stp; + else set_log_next(stp1, stp); + set_store(ml, 0); + } +#endif if (free_of(ml)) { unlink_free_chunk(ml); set_free(ml, 0); /* user reallocs free block */ diff --git a/modules/src/malloc/phys.c b/modules/src/malloc/phys.c index f87a2a01c..7f7d6ec16 100644 --- a/modules/src/malloc/phys.c +++ b/modules/src/malloc/phys.c @@ -32,6 +32,7 @@ create_chunk(p, n) assert(!last || p == (char *)phys_next_of(last) - mallink_size()); ml = (mallink *)(p + mallink_size()); /* bump ml */ + new_mallink(ml); started_working_on(ml); set_free(ml, 1); set_phys_prev(ml, last); @@ -60,6 +61,7 @@ truncate(ml, size) register mallink *new = (mallink *)((char *)ml + size); register mallink *ph_next = phys_next_of(ml); + new_mallink(new); set_free(new, 1); set_phys_prev(new, ml); set_phys_next(new, ph_next); -- 2.34.1