avoid using deallocated things during context dedtroy
authorAndy Green <andy.green@linaro.org>
Mon, 18 Jan 2016 03:49:41 +0000 (11:49 +0800)
committerAndy Green <andy.green@linaro.org>
Mon, 18 Jan 2016 04:07:07 +0000 (12:07 +0800)
Signed-off-by: Andy Green <andy.green@linaro.org>
lib/client.c
lib/context.c
lib/private-libwebsockets.h
lib/server.c

index 7dcd175..8b7176f 100644 (file)
@@ -785,7 +785,7 @@ check_accept:
 
        p = lws_hdr_simple_ptr(wsi, WSI_TOKEN_ACCEPT);
        if (strcmp(p, wsi->u.hdr.ah->initial_handshake_hash_base64)) {
-               lwsl_warn("lws_client_int_s_hs: accept %s wrong vs %s\n", p,
+               lwsl_warn("lws_client_int_s_hs: accept '%s' wrong vs '%s'\n", p,
                                  wsi->u.hdr.ah->initial_handshake_hash_base64);
                goto bail2;
        }
index 113901b..b66e098 100644 (file)
@@ -296,6 +296,8 @@ lws_context_destroy(struct lws_context *context)
        if (!context)
                return;
 
+       context->being_destroyed = 1;
+
        memset(&wsi, 0, sizeof(wsi));
        wsi.context = context;
 
index 77e37c1..92ea713 100644 (file)
@@ -600,6 +600,8 @@ struct lws_context {
        short max_http_header_data;
        short max_http_header_pool;
        short ah_count_in_use;
+
+       unsigned int being_destroyed:1;
 };
 
 enum {
index d535b81..c92401d 100644 (file)
@@ -152,7 +152,7 @@ _lws_server_listen_accept_flow_control(struct lws_context *context, int on)
        struct lws *wsi = context->wsi_listening;
        int n;
 
-       if (!wsi)
+       if (!wsi || context->being_destroyed)
                return 0;
 
        lwsl_debug("%s: wsi %p: state %d\n", __func__, (void *)wsi, on);