mirror of
https://github.com/microsoft/mimalloc.git
synced 2025-07-05 19:14:37 +03:00
ensure mem defined after remap
This commit is contained in:
parent
faac72b4ae
commit
707c196656
2 changed files with 20 additions and 2 deletions
1
src/os.c
1
src/os.c
|
@ -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);
|
return mi_os_remap_copy(p, size, newsize, alignment, memid, stats);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mi_track_mem_defined(newp, size);
|
||||||
newmemid.initially_committed = true;
|
newmemid.initially_committed = true;
|
||||||
if (p == NULL && extend_is_zero) {
|
if (p == NULL && extend_is_zero) {
|
||||||
newmemid.initially_zero = true;
|
newmemid.initially_zero = true;
|
||||||
|
|
|
@ -20,12 +20,14 @@ static void alloc_huge(void);
|
||||||
static void test_heap_walk(void);
|
static void test_heap_walk(void);
|
||||||
static void test_remap(bool start_remappable);
|
static void test_remap(bool start_remappable);
|
||||||
static void test_remap2(void);
|
static void test_remap2(void);
|
||||||
|
static void test_remap3(void);
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
mi_version();
|
mi_version();
|
||||||
mi_stats_reset();
|
mi_stats_reset();
|
||||||
|
|
||||||
test_remap2();
|
//test_remap2();
|
||||||
|
test_remap3();
|
||||||
//test_remap(true);
|
//test_remap(true);
|
||||||
|
|
||||||
// detect double frees and heap corruption
|
// 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);
|
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);
|
int* p = (int*)mi_malloc(356);
|
||||||
p = (int*)mi_realloc(p, 583);
|
p = (int*)mi_realloc(p, 583);
|
||||||
memset(p, '\0', 580);
|
memset(p, '\0', 580);
|
||||||
|
@ -230,6 +232,21 @@ static void test_remap2(void) {
|
||||||
mi_free(p);
|
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) {
|
static void test_remap(bool start_remappable) {
|
||||||
const size_t iterN = 100;
|
const size_t iterN = 100;
|
||||||
const size_t size0 = 64 * 1024 * 1024;
|
const size_t size0 = 64 * 1024 * 1024;
|
||||||
|
|
Loading…
Add table
Reference in a new issue