xamarin-macios
xamarin-macios copied to clipboard
[release/8.0.1xx-xcode15.1] [runtime] Fix memory leak with BlockLiteral descriptors. Fixes #20503.
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.
Could you refer to the file that is causing the problem? I guess it's outdated now