better check if a block was already freed
This commit is contained in:
parent
a726f7d49e
commit
d5c423adaf
|
@ -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))
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue