xamarin / xamarin-macios

.NET for iOS, Mac Catalyst, macOS, and tvOS provide open-source bindings of the Apple SDKs for use with .NET managed languages such as C#
Other
2.42k stars 504 forks source link

[runtime] Fix memory leak with BlockLiteral descriptors. Fixes #20503. #20556

Closed rolfbjarne closed 2 months ago

rolfbjarne commented 2 months ago

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.

vs-mobiletools-engineering-service2 commented 2 months ago

:books: [PR Build] Artifacts :books:

Packages generated

View packages * [xamarin.ios-17.3.0.408.pkg](https://dl.internalx.com/wrench/merge/dcc114bf080221a207c5fbb4c99d3fd9fa12019d/9524215/package/xamarin.ios-17.3.0.408.pkg) * [xamarin.mac-9.3.0.408.pkg](https://dl.internalx.com/wrench/merge/dcc114bf080221a207c5fbb4c99d3fd9fa12019d/9524215/package/xamarin.mac-9.3.0.408.pkg)

Pipeline on Agent Hash: [PR build]

vs-mobiletools-engineering-service2 commented 2 months ago

:computer: [PR Build] Tests on macOS X64 - Mac Sonoma (14) passed :computer:

:white_check_mark: All tests on macOS X64 - Mac Sonoma (14) passed.

Pipeline on Agent Hash: [PR build]

vs-mobiletools-engineering-service2 commented 2 months ago

:computer: [PR Build] Tests on macOS M1 - Mac Monterey (12) passed :computer:

:white_check_mark: All tests on macOS M1 - Mac Monterey (12) passed.

Pipeline on Agent Hash: [PR build]

vs-mobiletools-engineering-service2 commented 2 months ago

:computer: [PR Build] Tests on macOS M1 - Mac Ventura (13) passed :computer:

:white_check_mark: All tests on macOS M1 - Mac Ventura (13) passed.

Pipeline on Agent Hash: [PR build]

vs-mobiletools-engineering-service2 commented 2 months ago

:computer: [PR Build] Tests on macOS M1 - Mac Big Sur (11) passed :computer:

:white_check_mark: All tests on macOS M1 - Mac Big Sur (11) passed.

Pipeline on Agent Hash: [PR build]

vs-mobiletools-engineering-service2 commented 2 months ago

:computer: [CI Build] Windows Integration Tests passed :computer:

:white_check_mark: All Windows Integration Tests passed.

Pipeline on Agent Hash: 21a5a02fe2f97f9a5d1cf980d2f62941e5bede4f [PR build]

vs-mobiletools-engineering-service2 commented 2 months ago

:white_check_mark: API diff for current PR / commit

Legacy Xamarin (No breaking changes) * ~iOS~ (no change detected) * ~tvOS~ (no change detected) * ~watchOS~ (no change detected) * ~macOS~ (no change detected)
NET (empty diffs) * ~iOS~: (empty diff detected) * ~tvOS~: (empty diff detected) * ~MacCatalyst~: (empty diff detected) * ~macOS~: (empty diff detected)

:white_check_mark: API diff vs stable

Legacy Xamarin (No breaking changes) * iOS: [vsdrops](https://vsdrop.corp.microsoft.com/file/v1/xamarin-macios/detected-changes/20240503.3/9524215-1/;/stable-api-comparison/ios-api-diff.html) [gist](https://gist.github.com/vs-mobiletools-engineering-service2/8b7877643d79ab6102d8cc7dbb112735) (No breaking changes) * tvOS: [vsdrops](https://vsdrop.corp.microsoft.com/file/v1/xamarin-macios/detected-changes/20240503.3/9524215-1/;/stable-api-comparison/tvos-api-diff.html) [gist](https://gist.github.com/vs-mobiletools-engineering-service2/b39da463cc674f53ac3150c0ffae3ab6) (No breaking changes) * watchOS: [vsdrops](https://vsdrop.corp.microsoft.com/file/v1/xamarin-macios/detected-changes/20240503.3/9524215-1/;/stable-api-comparison/watchos-api-diff.html) [gist](https://gist.github.com/vs-mobiletools-engineering-service2/279b72f3c44373bbd8bfbb6839e4f128) (No breaking changes) * macOS: [vsdrops](https://vsdrop.corp.microsoft.com/file/v1/xamarin-macios/detected-changes/20240503.3/9524215-1/;/stable-api-comparison/mac-api-diff.html) [gist](https://gist.github.com/vs-mobiletools-engineering-service2/34bc3ff36d77e688994a36f5c4b81bb8) (No breaking changes)
.NET (No breaking changes) * iOS: [vsdrops](https://vsdrop.corp.microsoft.com/file/v1/xamarin-macios/detected-changes/20240503.3/9524215-1/;/stable-api-comparison/diff/dotnet/Microsoft.iOS.Ref/ref/net8.0/Microsoft.iOS.html) [gist](https://gist.github.com/vs-mobiletools-engineering-service2/8351abfcd0a59fce4dec8e0e3db932f3) (No breaking changes) * tvOS: [vsdrops](https://vsdrop.corp.microsoft.com/file/v1/xamarin-macios/detected-changes/20240503.3/9524215-1/;/stable-api-comparison/diff/dotnet/Microsoft.tvOS.Ref/ref/net8.0/Microsoft.tvOS.html) [gist](https://gist.github.com/vs-mobiletools-engineering-service2/2e5b94078251f144111e1f6f81080c12) (No breaking changes) * MacCatalyst: [vsdrops](https://vsdrop.corp.microsoft.com/file/v1/xamarin-macios/detected-changes/20240503.3/9524215-1/;/stable-api-comparison/diff/dotnet/Microsoft.MacCatalyst.Ref/ref/net8.0/Microsoft.MacCatalyst.html) [gist](https://gist.github.com/vs-mobiletools-engineering-service2/f45f7db0777e6b076eba7935c8f9919f) (No breaking changes) * macOS: [vsdrops](https://vsdrop.corp.microsoft.com/file/v1/xamarin-macios/detected-changes/20240503.3/9524215-1/;/stable-api-comparison/diff/dotnet/Microsoft.macOS.Ref/ref/net8.0/Microsoft.macOS.html) [gist](https://gist.github.com/vs-mobiletools-engineering-service2/37ab2218df511c71201e262c5215efe6) (No breaking changes) * Microsoft.iOS vs Microsoft.MacCatalyst: [vsdrops](https://vsdrop.corp.microsoft.com/file/v1/xamarin-macios/detected-changes/20240503.3/9524215-1/;/stable-api-comparison/diff/dotnet/iOS-MacCatalyst-diff/Microsoft.iOS.Ref/ref/net8.0/Microsoft.iOS.MacCatalyst.html) [gist](https://gist.github.com/vs-mobiletools-engineering-service2/6b1391adea66c184edf8195d3f2df7b4)
Legacy Xamarin (stable) vs .NET * iOS: [vsdrops](https://vsdrop.corp.microsoft.com/file/v1/xamarin-macios/detected-changes/20240503.3/9524215-1/;/stable-api-comparison/diff/dotnet/legacy-diff/Microsoft.iOS.Ref/ref/net8.0/Microsoft.iOS.html) [gist](https://gist.github.com/vs-mobiletools-engineering-service2/6df0d2aeaf1d96298610178765a84707) * tvOS: [vsdrops](https://vsdrop.corp.microsoft.com/file/v1/xamarin-macios/detected-changes/20240503.3/9524215-1/;/stable-api-comparison/diff/dotnet/legacy-diff/Microsoft.tvOS.Ref/ref/net8.0/Microsoft.tvOS.html) [gist](https://gist.github.com/vs-mobiletools-engineering-service2/5af356ee59be2b6061e8415068c9f39a) * macOS: [vsdrops](https://vsdrop.corp.microsoft.com/file/v1/xamarin-macios/detected-changes/20240503.3/9524215-1/;/stable-api-comparison/diff/dotnet/legacy-diff/Microsoft.macOS.Ref/ref/net8.0/Microsoft.macOS.html) [gist](https://gist.github.com/vs-mobiletools-engineering-service2/107e2957abf118d01dfefb9d8b7c859f)

:information_source: Generator diff

Generator Diff: vsdrops (html) vsdrops (raw diff) gist (raw diff) - Please review changes)

Pipeline on Agent Hash: 21a5a02fe2f97f9a5d1cf980d2f62941e5bede4f [PR build]

vs-mobiletools-engineering-service2 commented 2 months ago

:fire: [CI Build] Test results :fire:

Test results

:x: Tests failed on VSTS: test results

1 tests crashed, 24 tests failed, 53 tests passed.

Failures

:x: dotnettests tests (tvOS)

1 tests failed, 0 tests passed.
* DotNet tests: Failed (Execution failed with exit code 1)

Html Report (VSDrops) Download

:x: introspection tests

1 tests failed, 2 tests passed.
* introspection/Mac Catalyst [dotnet]/Debug [dotnet]: BuildFailure

Html Report (VSDrops) Download

:x: linker tests

20 tests failed, 7 tests passed.
* dont link/Mac [dotnet]/Debug [dotnet]: BuildFailure * dont link/Mac [dotnet]/Release [dotnet]: BuildFailure * dont link/Mac Catalyst [dotnet]/Debug [dotnet]: BuildFailure * dont link/Mac Catalyst [dotnet]/Release [dotnet]: BuildFailure * link sdk/Mac [dotnet]/Debug [dotnet]: BuildFailure * link sdk/Mac [dotnet]/Release [dotnet]: BuildFailure * link sdk/Mac Catalyst [dotnet]/Debug [dotnet]: BuildFailure * link sdk/Mac Catalyst [dotnet]/Release [dotnet]: BuildFailure * link all/Mac [dotnet]/Debug [dotnet]: BuildFailure * link all/Mac [dotnet]/Release [dotnet]: BuildFailure * link all/Mac Catalyst [dotnet]/Debug [dotnet]: BuildFailure * link all/Mac Catalyst [dotnet]/Release [dotnet]: BuildFailure ( (failed to parse the logs: The Writer is closed or in error state.)) * trimmode copy/Mac [dotnet]/Debug [dotnet]: BuildFailure ( (failed to parse the logs: The Writer is closed or in error state.)) * trimmode copy/Mac [dotnet]/Release [dotnet]: BuildFailure * trimmode copy/Mac Catalyst [dotnet]/Debug [dotnet]: BuildFailure * trimmode copy/Mac Catalyst [dotnet]/Release [dotnet]: BuildFailure * trimmode link/Mac [dotnet]/Debug [dotnet]: BuildFailure * trimmode link/Mac [dotnet]/Release [dotnet]: BuildFailure * trimmode link/Mac Catalyst [dotnet]/Debug [dotnet]: BuildFailure * trimmode link/Mac Catalyst [dotnet]/Release [dotnet]: BuildFailure ( (failed to parse the logs: The Writer is closed or in error state.))

Html Report (VSDrops) Download

:x: monotouch tests (tvOS)

:fire: Failed catastrophically on VSTS: test results - monotouch_tvos (no summary found).

Html Report (VSDrops) Download

:x: msbuild tests

2 tests failed, 0 tests passed.
* MSBuild tests/Tasks: Failed (Execution failed with exit code 4) * MSBuild tests/Integration: Failed (Execution failed with exit code 106)

Html Report (VSDrops) Download

Successes

:white_check_mark: cecil: All 1 tests passed. Html Report (VSDrops) Download :white_check_mark: dotnettests (iOS): All 1 tests passed. Html Report (VSDrops) Download :white_check_mark: dotnettests (MacCatalyst): All 1 tests passed. Html Report (VSDrops) Download :white_check_mark: dotnettests (macOS): All 1 tests passed. Html Report (VSDrops) Download :white_check_mark: dotnettests (Multiple platforms): All 1 tests passed. Html Report (VSDrops) Download :white_check_mark: framework: All 3 tests passed. Html Report (VSDrops) Download :white_check_mark: fsharp: All 2 tests passed. Html Report (VSDrops) Download :white_check_mark: generator: All 2 tests passed. Html Report (VSDrops) Download :white_check_mark: install-source: All 1 tests passed. Html Report (VSDrops) Download :white_check_mark: interdependent-binding-projects: All 2 tests passed. Html Report (VSDrops) Download :white_check_mark: mac-binding-project: All 1 tests passed. Html Report (VSDrops) Download :white_check_mark: mmp: All 2 tests passed. Html Report (VSDrops) Download :white_check_mark: mononative: All 2 tests passed. Html Report (VSDrops) Download :warning: monotouch (iOS): No tests selected. Html Report (VSDrops) Download :white_check_mark: monotouch (MacCatalyst): All 7 tests passed. Html Report (VSDrops) Download :white_check_mark: monotouch (macOS): All 8 tests passed. Html Report (VSDrops) Download :warning: monotouch (watchOS): No tests selected. Html Report (VSDrops) Download :white_check_mark: mtouch: All 1 tests passed. Html Report (VSDrops) Download :white_check_mark: xammac: All 3 tests passed. Html Report (VSDrops) Download :white_check_mark: xcframework: All 3 tests passed. Html Report (VSDrops) Download :white_check_mark: xtro: All 2 tests passed. Html Report (VSDrops) Download

Pipeline on Agent Hash: [PR build]

vs-mobiletools-engineering-service2 commented 2 months ago

:rocket: [CI Build] Test results :rocket:

Test results

:white_check_mark: All tests passed on VSTS: test results.

:tada: All 131 tests passed :tada:

Tests counts

:white_check_mark: cecil: All 1 tests passed. Html Report (VSDrops) Download :white_check_mark: dotnettests (iOS): All 1 tests passed. Html Report (VSDrops) Download :white_check_mark: dotnettests (MacCatalyst): All 1 tests passed. Html Report (VSDrops) Download :white_check_mark: dotnettests (macOS): All 1 tests passed. Html Report (VSDrops) Download :white_check_mark: dotnettests (Multiple platforms): All 1 tests passed. Html Report (VSDrops) Download :white_check_mark: dotnettests (tvOS): All 1 tests passed. [attempt 2] Html Report (VSDrops) Download :white_check_mark: framework: All 3 tests passed. Html Report (VSDrops) Download :white_check_mark: fsharp: All 2 tests passed. Html Report (VSDrops) Download :white_check_mark: generator: All 2 tests passed. Html Report (VSDrops) Download :white_check_mark: install-source: All 1 tests passed. Html Report (VSDrops) Download :white_check_mark: interdependent-binding-projects: All 2 tests passed. Html Report (VSDrops) Download :white_check_mark: introspection: All 8 tests passed. [attempt 2] Html Report (VSDrops) Download :white_check_mark: linker: All 65 tests passed. [attempt 2] Html Report (VSDrops) Download :white_check_mark: mac-binding-project: All 1 tests passed. Html Report (VSDrops) Download :white_check_mark: mmp: All 2 tests passed. Html Report (VSDrops) Download :white_check_mark: mononative: All 2 tests passed. Html Report (VSDrops) Download :warning: monotouch (iOS): No tests selected. Html Report (VSDrops) Download :white_check_mark: monotouch (MacCatalyst): All 7 tests passed. Html Report (VSDrops) Download :white_check_mark: monotouch (macOS): All 8 tests passed. Html Report (VSDrops) Download :white_check_mark: monotouch (tvOS): All 11 tests passed. [attempt 2] Html Report (VSDrops) Download :warning: monotouch (watchOS): No tests selected. Html Report (VSDrops) Download :white_check_mark: msbuild: All 2 tests passed. [attempt 2] Html Report (VSDrops) Download :white_check_mark: mtouch: All 1 tests passed. Html Report (VSDrops) Download :white_check_mark: xammac: All 3 tests passed. Html Report (VSDrops) Download :white_check_mark: xcframework: All 3 tests passed. Html Report (VSDrops) Download :white_check_mark: xtro: All 2 tests passed. Html Report (VSDrops) Download

Pipeline on Agent Hash: [PR build]

rolfbjarne commented 2 months ago

/sudo backport release/8.0.1xx-xcode15.1

vs-mobiletools-engineering-service2 commented 2 months ago

I couldn't create a backport to release/8.0.1xx-xcode15.1 for you. :( Please check the Action logs for more details.