Commit 5d5af62
Fix GCHandle leak in OSX SafeDeleteSslContext (#128325)
> [!NOTE]
> This PR was authored with help from GitHub Copilot.
The `GCHandle` allocated in `SafeDeleteSslContext.SslSetConnection` was
never freed, leaking one GCHandle table slot per SSL context on the
legacy macOS SecureTransport path.
Freeing it in `SafeDeleteSslContext.Dispose` races with in-flight native
`Read`/`Write` callbacks (reliably reproduced as a `Debug.Assert` crash
in
`SslStreamSniTest.SslStream_ServerCallbackAndLocalCertificateSelectionSet_Throws`).
Instead, ownership of the handle is moved into `SafeSslHandle` and freed
from its `ReleaseHandle`, which only runs after the ref count hits zero
and the native `SSLContext` is released, so no further callbacks can
fire.
Tested locally on osx-arm64: `System.Net.Security.Unit.Tests` (124) and
`System.Net.Security.Tests` functional (4964) all pass.
Fixes #128136
---------
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Jan Kotas <jkotas@microsoft.com>
Co-authored-by: Miha Zupan <mihazupan.zupan1@gmail.com>1 parent 822530f commit 5d5af62
2 files changed
Lines changed: 20 additions & 6 deletions
File tree
- src/libraries
- Common/src/Interop/OSX/System.Security.Cryptography.Native.Apple
- System.Net.Security/src/System/Net/Security/Pal.OSX
Lines changed: 15 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
460 | 460 | | |
461 | 461 | | |
462 | 462 | | |
| 463 | + | |
| 464 | + | |
| 465 | + | |
| 466 | + | |
| 467 | + | |
| 468 | + | |
| 469 | + | |
463 | 470 | | |
464 | 471 | | |
465 | 472 | | |
| |||
470 | 477 | | |
471 | 478 | | |
472 | 479 | | |
| 480 | + | |
| 481 | + | |
| 482 | + | |
| 483 | + | |
| 484 | + | |
| 485 | + | |
473 | 486 | | |
474 | 487 | | |
475 | 488 | | |
476 | 489 | | |
| 490 | + | |
| 491 | + | |
477 | 492 | | |
478 | 493 | | |
479 | 494 | | |
| |||
Lines changed: 5 additions & 6 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
191 | 191 | | |
192 | 192 | | |
193 | 193 | | |
194 | | - | |
| 194 | + | |
| 195 | + | |
195 | 196 | | |
196 | | - | |
| 197 | + | |
197 | 198 | | |
198 | 199 | | |
199 | 200 | | |
| |||
220 | 221 | | |
221 | 222 | | |
222 | 223 | | |
223 | | - | |
224 | | - | |
| 224 | + | |
225 | 225 | | |
226 | 226 | | |
227 | 227 | | |
| |||
255 | 255 | | |
256 | 256 | | |
257 | 257 | | |
258 | | - | |
259 | | - | |
| 258 | + | |
260 | 259 | | |
261 | 260 | | |
262 | 261 | | |
| |||
0 commit comments