@@ -71,14 +71,34 @@ internal override void AssignPendingDNSInfo(string userProtocol, string DNSCache
71
71
72
72
internal void ReadAsyncCallback ( SNIPacket packet , uint error )
73
73
{
74
- ReadAsyncCallback ( IntPtr . Zero , PacketHandle . FromManagedPacket ( packet ) , error ) ;
75
- _sessionHandle ? . ReturnPacket ( packet ) ;
74
+ SNIHandle sessionHandle = _sessionHandle ;
75
+ if ( sessionHandle != null )
76
+ {
77
+ ReadAsyncCallback ( IntPtr . Zero , PacketHandle . FromManagedPacket ( packet ) , error ) ;
78
+ sessionHandle ? . ReturnPacket ( packet ) ;
79
+ }
80
+ else
81
+ {
82
+ // clear the packet and drop it to GC because we no longer know how to return it to the correct owner
83
+ // this can only happen if a packet is in-flight when the _sessionHandle is cleared
84
+ packet . Release ( ) ;
85
+ }
76
86
}
77
87
78
88
internal void WriteAsyncCallback ( SNIPacket packet , uint sniError )
79
89
{
80
- WriteAsyncCallback ( IntPtr . Zero , PacketHandle . FromManagedPacket ( packet ) , sniError ) ;
81
- _sessionHandle ? . ReturnPacket ( packet ) ;
90
+ SNIHandle sessionHandle = _sessionHandle ;
91
+ if ( sessionHandle != null )
92
+ {
93
+ WriteAsyncCallback ( IntPtr . Zero , PacketHandle . FromManagedPacket ( packet ) , sniError ) ;
94
+ sessionHandle ? . ReturnPacket ( packet ) ;
95
+ }
96
+ else
97
+ {
98
+ // clear the packet and drop it to GC because we no longer know how to return it to the correct owner
99
+ // this can only happen if a packet is in-flight when the _sessionHandle is cleared
100
+ packet . Release ( ) ;
101
+ }
82
102
}
83
103
84
104
protected override void RemovePacketFromPendingList ( PacketHandle packet )
0 commit comments