Skip to content

Commit

Permalink
In make-tcp-socket, close stream (not just fd) when connect fails
Browse files Browse the repository at this point in the history
  • Loading branch information
xrme committed Jul 9, 2024
1 parent 4c6c0fc commit 35eb257
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion library/sockets.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -685,7 +685,19 @@ the socket is not connected."))
:port remote-port
:allow-other-keys t
keys))))
(%socket-connect fd socket-address timeout-in-milliseconds)))
(handler-bind
((socket-creation-error
(lambda (c)
(declare (ignore c))
;; When connect fails, the fd is no longer usable,
;; and must be closed. Because we've already made
;; a stream using this fd, close the fd by closing
;; the stream.
(close socket)
;; Don't try to close fd again in the unwind-protect
;; cleanup form.
(setq fd -1))))
(%socket-connect fd socket-address timeout-in-milliseconds))))
(setq fd -1)
socket))
(unless (< fd 0)
Expand Down

0 comments on commit 35eb257

Please sign in to comment.