Skip to content

Commit

Permalink
Merge pull request #5324 from AvaloniaUI/unmanaged-blob-fx
Browse files Browse the repository at this point in the history
Supporess finalization when UnmanagedBlob allocation failed
  • Loading branch information
Dan Walmsley committed Jan 20, 2021
2 parents 08d38bd + 8919949 commit 5e65954
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions src/Shared/PlatformSupport/StandardRuntimePlatform.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,20 @@ static UnmanagedBlob()

public UnmanagedBlob(StandardRuntimePlatform plat, int size)
{
if (size <= 0)
throw new ArgumentException("Positive number required", nameof(size));
_plat = plat;
_address = plat.Alloc(size);
GC.AddMemoryPressure(size);
Size = size;
try
{
if (size <= 0)
throw new ArgumentException("Positive number required", nameof(size));
_plat = plat;
_address = plat.Alloc(size);
GC.AddMemoryPressure(size);
Size = size;
}
catch
{
GC.SuppressFinalize(this);
throw;
}
#if DEBUG
_backtrace = Environment.StackTrace;
lock (_btlock)
Expand Down

0 comments on commit 5e65954

Please sign in to comment.