From 940a75503caa80de24f2b99a1fdfbbd6f593aef6 Mon Sep 17 00:00:00 2001
From: Andy Green <andy.green@linaro.org>
Date: Thu, 15 Oct 2015 08:34:21 +0800
Subject: [PATCH] avoid changing wrong revents if connection closed

As reported by Bruce Perens

http://ml.libwebsockets.org/pipermail/libwebsockets/2015-May/001814.html

Signed-off-by: Andy Green <andy.green@linaro.org>
---
 lib/service.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/lib/service.c b/lib/service.c
index 057b5692..a17496e7 100644
--- a/lib/service.c
+++ b/lib/service.c
@@ -400,9 +400,7 @@ libwebsocket_service_fd(struct libwebsocket_context *context,
 				if (m == our_fd) {
 					/* it was the guy we came to service! */
 					timed_out = 1;
-					/* mark as handled */
-					if (pollfd)
-						pollfd->revents = 0;
+					/* he's gone, no need to mark as handled */
 				}
 		}
 	}
@@ -619,7 +617,8 @@ close_and_handled:
 	lwsl_debug("Close and handled\n");
 	libwebsocket_close_and_free_session(context, wsi,
 						LWS_CLOSE_STATUS_NOSTATUS);
-	n = 1;
+	// pollfd points to something else after the close
+	return 1;
 
 handled:
 	pollfd->revents = 0;
-- 
GitLab