fixed a problem with the store: we sometimes lost some memory
authorceriel <none@none>
Mon, 17 Jul 1989 15:13:09 +0000 (15:13 +0000)
committerceriel <none@none>
Mon, 17 Jul 1989 15:13:09 +0000 (15:13 +0000)
modules/src/malloc/impl.h
modules/src/malloc/mal.c
modules/src/malloc/phys.c

index ed2d276..3b92fe8 100644 (file)
@@ -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)
index b7a72ac..e330910 100644 (file)
@@ -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 */
index f87a2a0..7f7d6ec 100644 (file)
@@ -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);