add heap region check to cfree

This commit is contained in:
daan 2019-07-23 15:54:47 -07:00
parent dd79b662f8
commit 3d6feead60
2 changed files with 4 additions and 1 deletions

View File

@ -38,7 +38,9 @@ size_t mi_malloc_usable_size(const void *p) mi_attr_noexcept {
}
void mi_cfree(void* p) mi_attr_noexcept {
mi_free(p);
if (mi_is_in_heap_region(p)) {
mi_free(p);
}
}
int mi_posix_memalign(void** p, size_t alignment, size_t size) mi_attr_noexcept {

View File

@ -106,6 +106,7 @@ static size_t mi_good_commit_size(size_t size) {
// Return if a pointer points into a region reserved by us.
bool mi_is_in_heap_region(const void* p) mi_attr_noexcept {
if (p==NULL) return false;
size_t count = mi_atomic_read(&regions_count);
for (size_t i = 0; i < count; i++) {
uint8_t* start = (uint8_t*)mi_atomic_read_ptr(&regions[i].start);