Skip to content

Commit

Permalink
Always zero-init if object contains pointers (#100265) (#100426)
Browse files Browse the repository at this point in the history
  • Loading branch information
VSadov authored Apr 15, 2024
1 parent 2d7642d commit 88be910
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/coreclr/nativeaot/Runtime/gcrhenv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,12 @@ Object* GcAllocInternal(MethodTable *pEEType, uint32_t uFlags, uintptr_t numElem
ASSERT(!pThread->IsDoNotTriggerGcSet());
ASSERT(pThread->IsCurrentThreadInCooperativeMode());

if (pEEType->ContainsPointers())
{
uFlags |= GC_ALLOC_CONTAINS_REF;
uFlags &= ~GC_ALLOC_ZEROING_OPTIONAL;
}

size_t cbSize = pEEType->get_BaseSize();

if (pEEType->HasComponentSize())
Expand Down
2 changes: 2 additions & 0 deletions src/libraries/System.Runtime/tests/System/GCTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1100,6 +1100,8 @@ private unsafe static void AllocateArrayPinned_ManagedValueType_CanRoundtripThro
byte* pointer = (byte*)Unsafe.AsPointer(ref array[0]);
var size = Unsafe.SizeOf<EmbeddedValueType<string>>();

GC.Collect();

for(int i = 0; i < length; ++i)
{
int idx = rng.Next(length);
Expand Down

0 comments on commit 88be910

Please sign in to comment.