Skip to content

Commit 98d3c36

Browse files
committed
fix Dispose
1 parent 7fbbb68 commit 98d3c36

File tree

7 files changed

+55
-36
lines changed

7 files changed

+55
-36
lines changed

shadowsocks-csharp/Controller/ProxyAuth.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,8 @@ private void Close()
9393
{
9494
CloseSocket(ref _connection);
9595
CloseSocket(ref _connectionUDP);
96+
97+
_config = null;
9698
}
9799

98100
bool AuthConnection(Socket connection, string authUser, string authPass)
@@ -584,6 +586,7 @@ private void Connect()
584586
{
585587
handler.Start(_remoteHeaderSendBuffer, _remoteHeaderSendBuffer.Length, "socks5");
586588
}
589+
Dispose();
587590
return;
588591
}
589592
}
@@ -596,9 +599,26 @@ private void Connect()
596599
{
597600
handler.Start(_remoteHeaderSendBuffer, _remoteHeaderSendBuffer.Length, local_sendback_protocol);
598601
}
602+
Dispose();
599603
return;
600604
}
605+
Dispose();
601606
Close();
602607
}
608+
609+
private void Dispose()
610+
{
611+
_transfer = null;
612+
_IPRange = null;
613+
614+
_firstPacket = null;
615+
_connection = null;
616+
_connectionUDP = null;
617+
618+
_connetionRecvBuffer = null;
619+
_remoteHeaderSendBuffer = null;
620+
621+
httpProxyState = null;
622+
}
603623
}
604624
}

shadowsocks-csharp/Model/Configuration.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public class PortMapConfigCache
6767
public class ServerSubscribe
6868
{
6969
private static string DEFAULT_FEED_URL = "https://raw.githubusercontent.com/breakwa11/breakwa11.github.io/master/free/freenodeplain.txt";
70-
private static string OLD_DEFAULT_FEED_URL = "https://raw.githubusercontent.com/breakwa11/breakwa11.github.io/master/free/freenode.txt";
70+
//private static string OLD_DEFAULT_FEED_URL = "https://raw.githubusercontent.com/breakwa11/breakwa11.github.io/master/free/freenode.txt";
7171

7272
public string URL = DEFAULT_FEED_URL;
7373
public string Group;

shadowsocks-csharp/Obfs/Auth.cs

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -183,10 +183,6 @@ public override byte[] ClientPostDecrypt(byte[] plaindata, int datalength, out i
183183
}
184184
return outdata;
185185
}
186-
187-
public override void Dispose()
188-
{
189-
}
190186
}
191187

192188
public class AuthSHA1V2 : VerifySimpleBase
@@ -410,10 +406,6 @@ public override byte[] ClientPostDecrypt(byte[] plaindata, int datalength, out i
410406
}
411407
return outdata;
412408
}
413-
414-
public override void Dispose()
415-
{
416-
}
417409
}
418410

419411
public class AuthSHA1V4 : VerifySimpleBase
@@ -656,10 +648,6 @@ public override byte[] ClientPostDecrypt(byte[] plaindata, int datalength, out i
656648
}
657649
return outdata;
658650
}
659-
660-
public override void Dispose()
661-
{
662-
}
663651
}
664652

665653
public class AuthAES128SHA1 : VerifySimpleBase
@@ -1255,17 +1243,20 @@ public override byte[] ClientUdpPostDecrypt(byte[] plaindata, int datalength, ou
12551243
return plaindata;
12561244
}
12571245

1258-
public override void Dispose()
1246+
protected override void Dispose(bool disposing)
12591247
{
12601248
#if PROTOCOL_STATISTICS
1261-
if (Server != null && Server.data != null && packet_cnt != null)
1249+
if (disposing)
12621250
{
1263-
AuthDataAes128 authData = Server.data as AuthDataAes128;
1264-
if (authData != null && authData.tree != null)
1251+
if (Server != null && Server.data != null && packet_cnt != null)
12651252
{
1266-
lock (authData)
1253+
AuthDataAes128 authData = Server.data as AuthDataAes128;
1254+
if (authData != null && authData.tree != null)
12671255
{
1268-
authData.tree.Update(packet_cnt);
1256+
lock (authData)
1257+
{
1258+
authData.tree.Update(packet_cnt);
1259+
}
12691260
}
12701261
}
12711262
}

shadowsocks-csharp/Obfs/HttpSimpleObfs.cs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -260,10 +260,6 @@ public override byte[] ClientDecode(byte[] encryptdata, int datalength, out int
260260
return outdata;
261261
}
262262
}
263-
264-
public override void Dispose()
265-
{
266-
}
267263
}
268264
public class TlsAuthData
269265
{
@@ -673,9 +669,5 @@ public override byte[] ClientDecode(byte[] encryptdata, int datalength, out int
673669
return encryptdata;
674670
}
675671
}
676-
677-
public override void Dispose()
678-
{
679-
}
680672
}
681673
}

shadowsocks-csharp/Obfs/ObfsBase.cs

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public virtual byte[] ClientUdpPostDecrypt(byte[] plaindata, int datalength, out
5555
outlength = datalength;
5656
return plaindata;
5757
}
58-
public abstract void Dispose();
58+
5959
public virtual object InitData()
6060
{
6161
return null;
@@ -96,5 +96,29 @@ public int GetTcpMSS()
9696
{
9797
return Server.tcp_mss;
9898
}
99+
100+
101+
#region IDisposable
102+
protected bool _disposed;
103+
104+
public void Dispose()
105+
{
106+
Dispose(true);
107+
GC.SuppressFinalize(this);
108+
}
109+
110+
protected virtual void Dispose(bool disposing)
111+
{
112+
lock (this)
113+
{
114+
if (_disposed)
115+
{
116+
return;
117+
}
118+
_disposed = true;
119+
}
120+
}
121+
#endregion
122+
99123
}
100124
}

shadowsocks-csharp/Obfs/Plain.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,5 @@ public override byte[] ClientDecode(byte[] encryptdata, int datalength, out int
3636
needsendback = false;
3737
return encryptdata;
3838
}
39-
40-
public override void Dispose()
41-
{
42-
}
4339
}
4440
}

shadowsocks-csharp/Obfs/VerifySimpleObfs.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -212,10 +212,6 @@ public override byte[] ClientPostDecrypt(byte[] plaindata, int datalength, out i
212212
}
213213
return outdata;
214214
}
215-
216-
public override void Dispose()
217-
{
218-
}
219215
}
220216

221217
}

0 commit comments

Comments
 (0)