@@ -17,6 +17,7 @@ internal sealed class SafeDeleteSslContext : SafeDeleteContext
17
17
// mapped from OSX error codes
18
18
private const int InitialBufferSize = 2048 ;
19
19
private readonly SafeSslHandle _sslContext ;
20
+ private readonly object _lock = new object ( ) ;
20
21
private ArrayBuffer _inputBuffer = new ArrayBuffer ( InitialBufferSize ) ;
21
22
private ArrayBuffer _outputBuffer = new ArrayBuffer ( InitialBufferSize ) ;
22
23
@@ -202,7 +203,7 @@ protected override void Dispose(bool disposing)
202
203
SafeSslHandle sslContext = _sslContext ;
203
204
if ( null != sslContext )
204
205
{
205
- lock ( _sslContext )
206
+ lock ( _lock )
206
207
{
207
208
_inputBuffer . Dispose ( ) ;
208
209
_outputBuffer . Dispose ( ) ;
@@ -225,7 +226,7 @@ private static unsafe int WriteToConnection(IntPtr connection, byte* data, void*
225
226
// but if we were to pool the buffers we would have a potential use-after-free issue.
226
227
try
227
228
{
228
- lock ( context )
229
+ lock ( context . _lock )
229
230
{
230
231
ulong length = ( ulong ) * dataLength ;
231
232
Debug . Assert ( length <= int . MaxValue ) ;
@@ -257,7 +258,7 @@ private static unsafe int ReadFromConnection(IntPtr connection, byte* data, void
257
258
258
259
try
259
260
{
260
- lock ( context )
261
+ lock ( context . _lock )
261
262
{
262
263
ulong toRead = ( ulong ) * dataLength ;
263
264
@@ -294,7 +295,7 @@ private static unsafe int ReadFromConnection(IntPtr connection, byte* data, void
294
295
295
296
internal void Write ( ReadOnlySpan < byte > buf )
296
297
{
297
- lock ( _sslContext )
298
+ lock ( _lock )
298
299
{
299
300
_inputBuffer . EnsureAvailableSpace ( buf . Length ) ;
300
301
buf . CopyTo ( _inputBuffer . AvailableSpan ) ;
@@ -306,7 +307,7 @@ internal void Write(ReadOnlySpan<byte> buf)
306
307
307
308
internal void ReadPendingWrites ( ref ProtocolToken token )
308
309
{
309
- lock ( _sslContext )
310
+ lock ( _lock )
310
311
{
311
312
if ( _outputBuffer . ActiveLength == 0 )
312
313
{
@@ -328,7 +329,7 @@ internal int ReadPendingWrites(byte[] buf, int offset, int count)
328
329
Debug . Assert ( count >= 0 ) ;
329
330
Debug . Assert ( count <= buf . Length - offset ) ;
330
331
331
- lock ( _sslContext )
332
+ lock ( _lock )
332
333
{
333
334
int limit = Math . Min ( count , _outputBuffer . ActiveLength ) ;
334
335
0 commit comments