/* leak.c 2.1 7/8/88 14:15:57 */
/* Copyright (c) 1987, Benjamin G. Zorn */
mpcell lt_hmem
[MP_HASH_SIZE
];
extern bool keeping_leaks
;
bool keeping_leaks
= TRUE
;
mp_new_sstk(nbytes
, scallstack
)
unsigned scallstack
[SHORT_CALLSTACK_SIZE
];
mpsstk newsstk
= (mpsstk
) malloc(MPSSTK_SIZE
);
sstk_allocs(newsstk
) = 1;
sstk_bytes_alloced(newsstk
) = nbytes
;
sstk_bytes_freed(newsstk
) = 0;
for (i
= 0; i
< SHORT_CALLSTACK_SIZE
; i
++) {
sstk_addrs(newsstk
)[i
] = scallstack
[i
];
unsigned addrs
[SHORT_CALLSTACK_SIZE
];
for (i
= 0; i
< SHORT_CALLSTACK_SIZE
; i
++) {
hash
= (tmp
>> 24 | (tmp
& 0xff00)) ^
(((tmp
& 0xff) << 8) | (tmp
& 0xff0000) >> 16);
return (hash
% MP_HASH_SIZE
);
int hash
= lt_hash(sstk_addrs(s
));
lt_hmem
[hash
] = mp_cons((int) s
, lt_hmem
[hash
]);
unsigned addrs
[SHORT_CALLSTACK_SIZE
];
int hash
= lt_hash(addrs
);
mpcell c
= lt_hmem
[hash
];
for (i
= 0; i
< SHORT_CALLSTACK_SIZE
; i
++) {
if (addrs
[i
] != haddrs
[i
]) {
} else if (i
== SHORT_CALLSTACK_SIZE
- 1) {
mp_add_leak_table(sstk
, nbytes
)
unsigned sstk
[SHORT_CALLSTACK_SIZE
];
if (!keeping_leaks
) return NULL
;
if (s
!= (mpsstk
) MP_NIL
) {
sstk_bytes_alloced(s
) += nbytes
;
s
= mp_new_sstk(nbytes
, sstk
);
mp_remove_leak_table(leakdata
, nbytes
)
if (!keeping_leaks
) return;
if (leakdata
!= (mpsstk
) MP_NIL
) {
sstk_bytes_freed(leakdata
) += nbytes
;
"mp_remove_leak_table -- free of unallocated object\n");
mp_print_leak_table(file
)
int abytes
= 0, fbytes
= 0;
/* sprintf(outbuf, "%10s %10s %10s %10s %-10s\n",
"allocs", "bytes", "frees", "bytes", "path");
write(file, outbuf, strlen(outbuf));
for (i
= 0; i
< MP_HASH_SIZE
; i
++) {
while (!mp_null(chain
)) {
s
= (mpsstk
) mp_car(chain
);
if (((sstk_allocs(s
) != sstk_frees(s
)) ||
(sstk_bytes_alloced(s
) != sstk_bytes_freed(s
)))) {
abytes
+= sstk_bytes_alloced(s
);
fbytes
+= sstk_bytes_freed(s
);
chain
= (mpcell
) mp_cdr(chain
);
printf(" a: %d f: %d\n", abytes, fbytes);
write(file
, "-2 -1 -1 -1\n", 12);
sprintf(outbuf
, "%d %d %d %d\n",
sstk_allocs(s
), sstk_bytes_alloced(s
),
sstk_frees(s
), sstk_bytes_freed(s
));
write(file
, outbuf
, strlen(outbuf
));
for (i
= 0; i
< SHORT_CALLSTACK_SIZE
; i
++) {
sprintf(outbuf
, "%d\n", sstk_addrs(s
)[i
]);
write(file
, outbuf
, strlen(outbuf
));
for (i
= 0; i
< MP_HASH_SIZE
; i
++) {
lt_hmem
[i
] = (mpcell
) MP_NIL
;