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 link_free_chunk(), unlink_free_chunk();
|
||||||
public mallink *first_present(), *search_free_list();
|
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 set_log_prev(ml,e) (_log_prev_of(ml) = (e))
|
||||||
#define log_prev_of(ml) (mallink *) (_log_prev_of(ml))
|
#define log_prev_of(ml) (mallink *) (_log_prev_of(ml))
|
||||||
|
#endif
|
||||||
|
|
||||||
#define set_log_next(ml,e) (_log_next_of(ml) = (e))
|
#define set_log_next(ml,e) (_log_next_of(ml) = (e))
|
||||||
#define log_next_of(ml) (mallink *) (_log_next_of(ml))
|
#define log_next_of(ml) (mallink *) (_log_next_of(ml))
|
||||||
|
|
||||||
|
|
|
@ -26,11 +26,11 @@
|
||||||
#define ILL_BREAK (char *)(-1) /* funny failure value */
|
#define ILL_BREAK (char *)(-1) /* funny failure value */
|
||||||
#endif
|
#endif
|
||||||
extern char *SBRK();
|
extern char *SBRK();
|
||||||
|
privatedata char *freed;
|
||||||
#ifdef STORE
|
#ifdef STORE
|
||||||
#define MAX_STORE 32
|
#define MAX_STORE 32
|
||||||
private do_free(), Xfree(), sell_out();
|
private do_free(), Xfree(), sell_out();
|
||||||
privatedata mallink *store[MAX_STORE];
|
privatedata mallink *store[MAX_STORE];
|
||||||
privatedata char *freed;
|
|
||||||
#endif STORE
|
#endif STORE
|
||||||
|
|
||||||
char *
|
char *
|
||||||
|
@ -49,6 +49,7 @@ malloc(n)
|
||||||
|
|
||||||
if (ml = *stp) {
|
if (ml = *stp) {
|
||||||
*stp = log_next_of(ml);
|
*stp = log_next_of(ml);
|
||||||
|
set_store(ml, 0);
|
||||||
check_mallinks("malloc fast exit");
|
check_mallinks("malloc fast exit");
|
||||||
return block_of_mallink(ml);
|
return block_of_mallink(ml);
|
||||||
}
|
}
|
||||||
|
@ -152,7 +153,7 @@ Xfree()
|
||||||
#ifdef STORE
|
#ifdef STORE
|
||||||
|
|
||||||
freed = 0;
|
freed = 0;
|
||||||
if (free_of(ml))
|
if (free_of(ml) || in_store(ml))
|
||||||
return; /* user frees free block */
|
return; /* user frees free block */
|
||||||
if (size_of(ml) <= MAX_STORE*MIN_SIZE) {
|
if (size_of(ml) <= MAX_STORE*MIN_SIZE) {
|
||||||
/* return to store */
|
/* return to store */
|
||||||
|
@ -160,6 +161,7 @@ Xfree()
|
||||||
|
|
||||||
set_log_next(ml, *stp);
|
set_log_next(ml, *stp);
|
||||||
*stp = ml;
|
*stp = ml;
|
||||||
|
set_store(ml, 1);
|
||||||
check_mallinks("free fast exit");
|
check_mallinks("free fast exit");
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -283,6 +285,7 @@ sell_out() {
|
||||||
|
|
||||||
while (ml) {
|
while (ml) {
|
||||||
*stp = log_next_of(ml);
|
*stp = log_next_of(ml);
|
||||||
|
set_store(ml, 0);
|
||||||
do_free(ml);
|
do_free(ml);
|
||||||
ml = *stp;
|
ml = *stp;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue