浏览代码

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>