xamarin-macios icon indicating copy to clipboard operation
xamarin-macios copied to clipboard

[release/8.0.1xx-xcode15.1] [runtime] Fix memory leak with BlockLiteral descriptors. Fixes #20503.

Open rolfbjarne opened this issue 1 year ago • 1 comments
trafficstars

We're using two different functions to atomically decrement a reference count, the native atomic_fetch_sub and the managed Interlocked.Decrement.

Unfortunately the return value is not the same: atomic_fetch_sub returns the original value before the subtraction, while Interlocked.Decrement returns the subtracted value, while our code assumed the functions behaved the same. This resulted in a memory leak, because we'd incorrectly expect 0 to be returned from atomic_fetch_sub when the reference count reaches zero, and thus not detect when the descriptor a block should be freed.

The fix is to update the expected return value from atomic_fetch_sub to be 1 instead of 0.

Fixes https://github.com/xamarin/xamarin-macios/issues/20503.

Backport of #20556.

rolfbjarne avatar May 06 '24 07:05 rolfbjarne

Could you refer to the file that is causing the problem? I guess it's outdated now

RS-labhub avatar Oct 09 '24 05:10 RS-labhub