From d7b96f478bd24f75b093a05e52131cf754ab7cd4 Mon Sep 17 00:00:00 2001 From: Yuriy Glukhov Date: Wed, 1 Nov 2017 11:16:44 +0200 Subject: [PATCH] Fixed crash in case of ssl error in SSLShutdown (#6662) --- lib/pure/net.nim | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/pure/net.nim b/lib/pure/net.nim index 215a301b66..a405ce1bda 100644 --- a/lib/pure/net.nim +++ b/lib/pure/net.nim @@ -857,13 +857,16 @@ proc close*(socket: Socket) = # shutdown i.e not wait for the peers "close notify" alert with a second # call to SSLShutdown let res = SSLShutdown(socket.sslHandle) - SSLFree(socket.sslHandle) - socket.sslHandle = nil if res == 0: discard elif res != 1: socketError(socket, res) finally: + when defineSsl: + if socket.isSSL and socket.sslHandle != nil: + SSLFree(socket.sslHandle) + socket.sslHandle = nil + socket.fd.close() proc toCInt*(opt: SOBool): cint =