[Libwebsockets] #331 client application crashes in libwebsocket_context_destroy on flaky network tests

Andy Green andy at warmcat.com
Sun Oct 18 12:39:39 CEST 2015



On 18 October 2015 14:19:20 GMT+08:00, Vikas Gahlan <vikas.gahlan at chargepoint.com> wrote:
>Attached patch work for me.
>
>Here is exact trace flow of the crash:
>
>libwebsocket_client_connect_2
>libwebsocket_client_connect_2: address mywebsocket.com
>closed
>libwebsocket_context_destroy
>close: just_kill_connection
>remove_wsi_socket_from_fds: wsi=0x7a0d8, sock=9, fds pos=1
>
>
>below fix works for me:
>
>From 300e50b2fe6a033a109d5f1f15208cb8490363e4 Mon Sep 17 00:00:00 2001
>From: vgahlan-cpi <vikas.gahlan at chargepoint.com>
>Date: Sat, 17 Oct 2015 22:40:23 -0700
>Subject: [PATCH] fdpolllist cleanup requires if wsi socket exists in
>fdtable
>to avoid double free in libwebsocket_context_destroy
>
>---
>lib/client-handshake.c | 9 ++++++---
>1 file changed, 6 insertions(+), 3 deletions(-)
>
>diff --git a/lib/client-handshake.c b/lib/client-handshake.c
>index 7293a41..d7d72e6 100644
>--- a/lib/client-handshake.c
>+++ b/lib/client-handshake.c
>@@ -291,9 +291,12 @@ struct libwebsocket
>*libwebsocket_client_connect_2(
>        return wsi;
>
>oom4:
>-       lws_free(wsi->u.hdr.ah);
>-       lws_free(wsi);
>-       return NULL;
>+        /*In case wsi added successfully in fd polllist, clean-up
>requires for fdtable and session data properly using
>libwebsocket_close_and_free_session().*/
>+        if(wsi->position_in_fds_table < 0  || wsi->sock < 0 ){

Thanks... this definitely is a real problem, but the fix needs to be a bit closer to the source of the problem I think.

I'll push an alternative fix for you to try in the next minutes.

-Andy

>+                lws_free(wsi->u.hdr.ah);
>+                lws_free(wsi);
>+                return NULL;
>+        }
>
>failed:
>        libwebsocket_close_and_free_session(context, wsi,
>--
>1.8.3.1
>
>Vikas Gahlan
>ChargePoint | chargepoint.com
>Ofiice: +91-124-4889450 Ext. 464 | Mobile +91-9873232008
>
>
>
>
>
>
>
>
>This email and any attachments are intended for the sole use of the
>intended recipient(s) and
>contain(s) confidential information that may be proprietary, privileged
>or copyrighted under
>applicable law. If you are not the intended recipient, do not read,
>copy, or forward this email
>message or any attachments and delete this email message and any
>attachments immediately.
>
>------------------------------------------------------------------------
>
>_______________________________________________
>Libwebsockets mailing list
>Libwebsockets at ml.libwebsockets.org
>http://ml.libwebsockets.org/mailman/listinfo/libwebsockets




More information about the Libwebsockets mailing list