From 15d11515b77c925b884397217d56ae34cd7dd44a Mon Sep 17 00:00:00 2001 From: Socolin Date: Fri, 19 Dec 2025 00:07:37 -0500 Subject: [PATCH] Fix concurrency problem with MemoryAllocatorValidator --- tests/ImageSharp.Tests/MemoryAllocatorValidator.cs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/tests/ImageSharp.Tests/MemoryAllocatorValidator.cs b/tests/ImageSharp.Tests/MemoryAllocatorValidator.cs index 395dfd455f..2afa5fdc9d 100644 --- a/tests/ImageSharp.Tests/MemoryAllocatorValidator.cs +++ b/tests/ImageSharp.Tests/MemoryAllocatorValidator.cs @@ -22,7 +22,10 @@ public static class MemoryAllocatorValidator TestMemoryDiagnostics backing = LocalInstance.Value; if (backing != null) { - backing.TotalRemainingAllocated--; + lock (backing) + { + backing.TotalRemainingAllocated--; + } } } @@ -31,8 +34,11 @@ public static class MemoryAllocatorValidator TestMemoryDiagnostics backing = LocalInstance.Value; if (backing != null) { - backing.TotalAllocated++; - backing.TotalRemainingAllocated++; + lock (backing) + { + backing.TotalAllocated++; + backing.TotalRemainingAllocated++; + } } }