Return NULL if the handshake failed to complete,
libwebsocket_service_fd closes and frees the websocket in that case.
diff --git a/lib/client-handshake.c b/lib/client-handshake.c
index ceb5f76..556b518 100644
--- a/lib/client-handshake.c
+++ b/lib/client-handshake.c
@@ -138,9 +138,15 @@
wsi->mode = LWS_CONNMODE_WS_CLIENT_ISSUE_HANDSHAKE;
pfd.fd = wsi->sock;
pfd.revents = POLLIN;
- if (libwebsocket_service_fd(context, &pfd) < 0)
+
+ n = libwebsocket_service_fd(context, &pfd);
+
+ if (n < 0)
goto oom4;
+ if (n) /* returns 1 on failure after closing wsi */
+ return NULL;
+
return wsi;
oom4: