fixed a problem with the store: we sometimes lost some memory

This commit is contained in:
ceriel 1989-07-17 15:13:09 +00:00
parent 09a52b8cf2
commit b1ee8fe36b
3 changed files with 20 additions and 0 deletions

View file

@ -56,6 +56,10 @@ typedef union _inf mallink;
#define checksum_of(ml) (_checksum_of(ml)) #define checksum_of(ml) (_checksum_of(ml))
#endif CHECK #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 block_of_mallink(ml) ((char *)ml)
#define mallink_of_block(addr) ((mallink *)addr) #define mallink_of_block(addr) ((mallink *)addr)

View file

@ -232,6 +232,20 @@ realloc(addr, n)
} }
ml = mallink_of_block(addr); ml = mallink_of_block(addr);
if (n < MIN_SIZE) n = align(MIN_SIZE); else n = align(n); 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)) { if (free_of(ml)) {
unlink_free_chunk(ml); unlink_free_chunk(ml);
set_free(ml, 0); /* user reallocs free block */ set_free(ml, 0); /* user reallocs free block */

View file

@ -32,6 +32,7 @@ create_chunk(p, n)
assert(!last || p == (char *)phys_next_of(last) - mallink_size()); assert(!last || p == (char *)phys_next_of(last) - mallink_size());
ml = (mallink *)(p + mallink_size()); /* bump ml */ ml = (mallink *)(p + mallink_size()); /* bump ml */
new_mallink(ml);
started_working_on(ml); started_working_on(ml);
set_free(ml, 1); set_free(ml, 1);
set_phys_prev(ml, last); set_phys_prev(ml, last);
@ -60,6 +61,7 @@ truncate(ml, size)
register mallink *new = (mallink *)((char *)ml + size); register mallink *new = (mallink *)((char *)ml + size);
register mallink *ph_next = phys_next_of(ml); register mallink *ph_next = phys_next_of(ml);
new_mallink(new);
set_free(new, 1); set_free(new, 1);
set_phys_prev(new, ml); set_phys_prev(new, ml);
set_phys_next(new, ph_next); set_phys_next(new, ph_next);