{"action":"created","issue":{"url":"https://api.github.com/repos/warmcat/libwebsockets/issues/394","labels_url":"https://api.github.com/repos/warmcat/libwebsockets/issues/394/labels{/name}","comments_url":"https://api.github.com/repos/warmcat/libwebsockets/issues/394/comments","events_url":"https://api.github.com/repos/warmcat/libwebsockets/issues/394/events","html_url":"https://github.com/warmcat/libwebsockets/issues/394","id":125742670,"number":394,"title":"Connecting to an invalid websocket URI will trigger assertion","user":{"login":"dumganhar","id":493372,"avatar_url":"https://avatars.githubusercontent.com/u/493372?v=3","gravatar_id":"","url":"https://api.github.com/users/dumganhar","html_url":"https://github.com/dumganhar","followers_url":"https://api.github.com/users/dumganhar/followers","following_url":"https://api.github.com/users/dumganhar/following{/other_user}","gists_url":"https://api.github.com/users/dumganhar/gists{/gist_id}","starred_url":"https://api.github.com/users/dumganhar/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dumganhar/subscriptions","organizations_url":"https://api.github.com/users/dumganhar/orgs","repos_url":"https://api.github.com/users/dumganhar/repos","events_url":"https://api.github.com/users/dumganhar/events{/privacy}","received_events_url":"https://api.github.com/users/dumganhar/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":39,"created_at":"2016-01-09T06:51:50Z","updated_at":"2016-01-14T03:48:46Z","closed_at":null,"body":"### Libwebsockets Version I used\r\n\r\nThe latest master branch .\r\n\r\n### How to reproduce?\r\n\r\nUses libwebsockets as a client, and connect to `ws://invalidurl.com`\r\nCode will go to\r\n\r\n```c++\r\nint\r\nlws_client_interpret_server_handshake(struct lws *wsi)\r\n{\r\n...\r\n...\r\n\tif (lws_hdr_total_length(wsi, WSI_TOKEN_ACCEPT) == 0) {\r\n\t\tlwsl_info(\"no ACCEPT\\n\");\r\n\t\tp = lws_hdr_simple_ptr(wsi, WSI_TOKEN_HTTP);\r\n\t\tisErrorCodeReceived = 1;\r\n\t\tgoto bail3;   // will go to here\r\n\t}\r\n...\r\n...\r\n\r\nbail3:\r\n\tlws_free_set_NULL(wsi->u.ws.rx_user_buffer);   // will go to here, since wsi->u is a union, free the memory of wsi->u.ws.rx_user_buffer will make `wsi->u.hdr.ah` to be nullptr\r\n\tclose_reason = LWS_CLOSE_STATUS_NOSTATUS;\r\n\r\nbail2:\r\n...\r\n...\r\n\t/* free up his parsing allocations */\r\n\tlws_free_header_table(wsi);   // will go to here\r\n\tlws_close_free_wsi(wsi, close_reason);\r\n\r\n\treturn 1;\r\n}\r\n\r\n```\r\n\r\n```c++\r\nint lws_free_header_table(struct lws *wsi)\r\n{\r\n\tstruct lws_context *context = wsi->context;\r\n\r\n\tlwsl_debug(\"%s: wsi %p: ah %p (count = %d)\\n\", __func__, (void *)wsi,\r\n\t\t (void *)wsi->u.hdr.ah, context->ah_count_in_use);\r\n\r\n\tassert(wsi->u.hdr.ah); // assertion happens, how to fix it?\r\n\tif (!wsi->u.hdr.ah)\r\n\t\treturn 0;\r\n```\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/warmcat/libwebsockets/issues/comments/171521148","html_url":"https://github.com/warmcat/libwebsockets/issues/394#issuecomment-171521148","issue_url":"https://api.github.com/repos/warmcat/libwebsockets/issues/394","id":171521148,"user":{"login":"lws-team","id":15154525,"avatar_url":"https://avatars.githubusercontent.com/u/15154525?v=3","gravatar_id":"","url":"https://api.github.com/users/lws-team","html_url":"https://github.com/lws-team","followers_url":"https://api.github.com/users/lws-team/followers","following_url":"https://api.github.com/users/lws-team/following{/other_user}","gists_url":"https://api.github.com/users/lws-team/gists{/gist_id}","starred_url":"https://api.github.com/users/lws-team/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lws-team/subscriptions","organizations_url":"https://api.github.com/users/lws-team/orgs","repos_url":"https://api.github.com/users/lws-team/repos","events_url":"https://api.github.com/users/lws-team/events{/privacy}","received_events_url":"https://api.github.com/users/lws-team/received_events","type":"User","site_admin":false},"created_at":"2016-01-14T03:48:46Z","updated_at":"2016-01-14T03:48:46Z","body":"Yeah... but the test client keeps retrying the connection.  Count the number of times it says \"dumb: connecting\" and \"dumb: ...CONNECTION_ERROR\".  In that case there is one error report per connection attempt as it should be.\r\n\r\nHowever this is the same as the first problem, the \"supporting documentation\" to reproduce or understand the problem is wrong from your side, but the problem you have underneath is real.\r\n\r\nI ignored not being able to reproduce it and went looking instead at how that could happen in the code and found a way.  I pushed a patch that should solve it.\r\n\r\n"}}