ensure mem defined after remap

This commit is contained in:
daanx 2023-05-18 18:08:06 -07:00
parent faac72b4ae
commit 707c196656
2 changed files with 20 additions and 2 deletions

View file

@ -552,6 +552,7 @@ void* _mi_os_remap(void* p, size_t size, size_t newsize, mi_memid_t* memid, mi_s
return mi_os_remap_copy(p, size, newsize, alignment, memid, stats);
}
mi_track_mem_defined(newp, size);
newmemid.initially_committed = true;
if (p == NULL && extend_is_zero) {
newmemid.initially_zero = true;

View file

@ -20,12 +20,14 @@ static void alloc_huge(void);
static void test_heap_walk(void);
static void test_remap(bool start_remappable);
static void test_remap2(void);
static void test_remap3(void);
int main() {
mi_version();
mi_stats_reset();
test_remap2();
//test_remap2();
test_remap3();
//test_remap(true);
// detect double frees and heap corruption
@ -221,7 +223,7 @@ static void test_heap_walk(void) {
mi_heap_visit_blocks(heap, true, &test_visit, NULL);
}
static void test_remap2(void) {
static void test_remap2(void) { // By Jason Gibson
int* p = (int*)mi_malloc(356);
p = (int*)mi_realloc(p, 583);
memset(p, '\0', 580);
@ -230,6 +232,21 @@ static void test_remap2(void) {
mi_free(p);
}
static void test_remap3(void) { // by Jason Gibson
int* x = (int*)mi_malloc(438);
x = (int*)mi_realloc(x, 1500705);
x = (int*)mi_realloc(x, 3000711);
x = (int*)mi_realloc(x, 6000723);
x = (int*)mi_realloc(x, 10500741);
x = (int*)mi_realloc(x, 16500765);
x = (int*)mi_realloc(x, 25500801);
x = (int*)mi_realloc(x, 39000855);
x = (int*)mi_realloc(x, 60000939);
mi_free(x);
}
static void test_remap(bool start_remappable) {
const size_t iterN = 100;
const size_t size0 = 64 * 1024 * 1024;