Skip to content

Commit ce81388

Browse files
authored
Fix some alloc-dealloc mismatches found by ASAN (#66964)
* Fix some alloc-dealloc mismatches found by ASAN * Define new static
1 parent cde8b0b commit ce81388

File tree

3 files changed

+14
-4
lines changed

3 files changed

+14
-4
lines changed

src/coreclr/gc/gc.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34695,7 +34695,7 @@ void gc_heap::background_grow_c_mark_list()
3469534695
assert (new_c_mark_list);
3469634696
memcpy (new_c_mark_list, c_mark_list, c_mark_list_length*sizeof(uint8_t*));
3469734697
c_mark_list_length = c_mark_list_length*2;
34698-
delete c_mark_list;
34698+
delete[] c_mark_list;
3469934699
c_mark_list = new_c_mark_list;
3470034700
}
3470134701
}

src/coreclr/vm/virtualcallstub.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,8 @@ UINT32 STUB_COLLIDE_WRITE_PCT = 100;
103103
UINT32 STUB_COLLIDE_MONO_PCT = 0;
104104
#endif // STUB_LOGGING
105105

106+
FastTable::NumCallStubs_t FastTable::NumCallStubs;
107+
106108
FastTable* BucketTable::dead = NULL; //linked list of the abandoned buckets
107109

108110
DispatchCache *g_resolveCache = NULL; //cache of dispatch stubs for in line lookup by resolve stubs.
@@ -3346,7 +3348,7 @@ void BucketTable::Reclaim()
33463348
while (list)
33473349
{
33483350
size_t next = list->contents[CALL_STUB_DEAD_LINK];
3349-
delete [] (size_t*)list;
3351+
delete list;
33503352
list = (FastTable*) next;
33513353
}
33523354
}

src/coreclr/vm/virtualcallstub.h

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1567,8 +1567,7 @@ class FastTable
15671567
while (size < numberOfEntries) {size = size<<1;}
15681568
// if (size == CALL_STUB_MIN_ENTRIES)
15691569
// size += 3;
1570-
size_t* bucket = new size_t[(sizeof(FastTable)/sizeof(size_t))+size+CALL_STUB_FIRST_INDEX];
1571-
FastTable* table = new (bucket) FastTable();
1570+
FastTable* table = new (NumCallStubs, size) FastTable();
15721571
table->InitializeContents(size);
15731572
return table;
15741573
}
@@ -1592,6 +1591,15 @@ class FastTable
15921591
//we have an unused cell to use as a temp at bucket[CALL_STUB_DEAD_LINK==2],
15931592
//and the table starts at bucket[CALL_STUB_FIRST_INDEX==3],
15941593
size_t contents[0];
1594+
1595+
void* operator new(size_t) = delete;
1596+
1597+
static struct NumCallStubs_t {} NumCallStubs;
1598+
1599+
void* operator new(size_t baseSize, NumCallStubs_t, size_t numCallStubs)
1600+
{
1601+
return ::operator new(baseSize + (numCallStubs + CALL_STUB_FIRST_INDEX) * sizeof(size_t));
1602+
}
15951603
};
15961604
#ifdef _MSC_VER
15971605
#pragma warning(pop)

0 commit comments

Comments
 (0)