소스 검색

Avoid initializing HostKeyEventArgs when there are no event handlers registered.

Gert Driesen 11 년 전
부모
커밋
e1c620bfd2
1개의 변경된 파일6개의 추가작업 그리고 5개의 파일을 삭제
  1. 6 5
      Renci.SshClient/Renci.SshNet/Security/KeyExchange.cs

+ 6 - 5
Renci.SshClient/Renci.SshNet/Security/KeyExchange.cs

@@ -290,14 +290,15 @@ namespace Renci.SshNet.Security
         /// </returns>
         protected bool CanTrustHostKey(KeyHostAlgorithm host)
         {
-            var args = new HostKeyEventArgs(host);
-
-            if (this.HostKeyReceived != null)
+            var handlers = HostKeyReceived;
+            if (handlers != null)
             {
-                this.HostKeyReceived(this, args);
+                var args = new HostKeyEventArgs(host);
+                handlers(this, args);
+                return args.CanTrust;
             }
 
-            return args.CanTrust;
+            return true;
         }
 
         /// <summary>