mirror of
https://github.com/opnsense/src.git
synced 2026-06-09 00:32:25 -04:00
Add two KASSERTS which trigger if free(9) would drag the "memuse" statistic
for a malloc bucket under zero. This typically happens if you malloc(9) from one bucket and free to another.
This commit is contained in:
parent
3fd530f7ec
commit
8cb72d6174
1 changed files with 6 additions and 0 deletions
|
|
@ -283,6 +283,9 @@ free(addr, type)
|
|||
if (addr == NULL)
|
||||
return;
|
||||
|
||||
KASSERT(ksp->ks_memuse > 0,
|
||||
("malloc(9)/free(9) confusion.\n%s",
|
||||
"Probably freeing with wrong type, but maybe not here."));
|
||||
size = 0;
|
||||
|
||||
slab = vtoslab((vm_offset_t)addr & (~UMA_SLAB_MASK));
|
||||
|
|
@ -318,6 +321,9 @@ free(addr, type)
|
|||
uma_large_free(slab);
|
||||
}
|
||||
mtx_lock(&ksp->ks_mtx);
|
||||
KASSERT(size <= ksp->ks_memuse,
|
||||
("malloc(9)/free(9) confusion.\n%s",
|
||||
"Probably freeing with wrong type, but maybe not here."));
|
||||
ksp->ks_memuse -= size;
|
||||
ksp->ks_inuse--;
|
||||
mtx_unlock(&ksp->ks_mtx);
|
||||
|
|
|
|||
Loading…
Reference in a new issue