Fixed crash issue on destroying websocket and applied exception codes 43/107743/3 accepted/tizen/common/20161230.055055 accepted/tizen/mobile/20170101.223856 accepted/tizen/tv/20170101.223912 accepted/tizen/wearable/20170101.223931 submit/tizen/20161230.043851
authorkmook <kmook.choi@samsung.com>
Thu, 29 Dec 2016 12:39:29 +0000 (21:39 +0900)
committerKyoung-Mook Choi <kmook.choi@samsung.com>
Fri, 30 Dec 2016 02:25:51 +0000 (18:25 -0800)
Change-Id: I551f4347ed8ccfa9b2f62bbe3723c6b9dacd6682
Signed-off-by: kmook <kmook.choi@samsung.com>
(cherry picked from commit c690e5e589bae8f34de120252307db154d82bb32)

msf_tizen_client/src/Application.cpp
msf_tizen_client/src/Channel.cpp
msf_tizen_client/src/Clients.cpp

index f4521b9..a4f7152 100755 (executable)
@@ -185,7 +185,7 @@ void Application::start()
 {
        Clients *clientstemp = Channel::getclients();
 
-       if (clientstemp->getHost() == NULL) {
+       if (!clientstemp || clientstemp->getHost() == NULL) {
                waitForOnReady = true;
        }
 
index 814fd74..a233859 100755 (executable)
@@ -880,12 +880,25 @@ int Channel::writeSocket(Channel* ch_p)
 int Channel::callback_lws_mirror(struct lws *wsi,
                                                                 enum lws_callback_reasons reason, void *user,
                                                                 void *in, size_t len) {
-       void *user_data;
+       void *user_data = NULL;
        Channel *this_ptr = NULL;
+       if (wsi == NULL) {
+               MSF_DBG("wsi is NULL");
+               return -1;
+       }
        struct lws_context *context = lws_get_context(wsi);
-       user_data = lws_context_user(context);
+
+       if (context != NULL) {
+               user_data = lws_context_user(context);
+       }
+
        this_ptr = static_cast<Channel *>(user_data);
 
+       if (this_ptr == NULL) {
+               // it means Channel object was deleted
+               return -1;
+       }
+
        if (channel_alive_map.find(this_ptr) != channel_alive_map.end()) {
                if (channel_alive_map[this_ptr] == 0) {
                        return -1;
@@ -909,11 +922,6 @@ int Channel::callback_lws_mirror(struct lws *wsi,
                break;
 
        case LWS_CALLBACK_CLIENT_RECEIVE:
-               if (this_ptr == NULL) {
-                       // it means Channel object was deleted
-                       return -1;
-               }
-
                if (lws_frame_is_binary(wsi)) {
                        MSF_DBG("BINARY MESSAGE ARRIVED. len:%d", len);
                        // header needs to be parsed on first chunk
@@ -961,6 +969,7 @@ int Channel::callback_lws_mirror(struct lws *wsi,
                                                this_ptr->cl_payload_size = 0;
                                                this_ptr->is_header_parsed = false;
                                                this_ptr->eventType.clear();
+                                               this_ptr->data.clear();
                                        }
                                }
                        } else {
@@ -989,6 +998,7 @@ int Channel::callback_lws_mirror(struct lws *wsi,
                                                this_ptr->cl_payload_size = 0;
                                                this_ptr->is_header_parsed = false;
                                                this_ptr->eventType.clear();
+                                               this_ptr->data.clear();
                                        }
                                }
                        }
@@ -1025,6 +1035,7 @@ int Channel::callback_lws_mirror(struct lws *wsi,
                                        this_ptr->cl_data = NULL;
                                        this_ptr->cl_data_size = 0;
                                        this_ptr->eventType.clear();
+                                       this_ptr->data.clear();
                                }
                        }
                }
@@ -1432,10 +1443,9 @@ void Channel::createWebsocket(void *att) {
 
 void Channel::writeRequest()
 {
-       lws_callback_on_writable(wsi_mirror);
-       if (pthread_self() != socketThreadId) {
-               MSF_DBG("current thread is different from websocket thread => lws_cancel_service()");
-               lws_cancel_service(lws_get_context(wsi_mirror)); // to exit from poll() inside of lws_service()
+       MSF_DBG("writeRequest start");
+       if (wsi_mirror != NULL) {
+               lws_callback_on_writable(wsi_mirror);
        }
 }
 
@@ -1744,9 +1754,6 @@ void Channel::handleWsiDestroy()
 {
        if (!isCommunicated) {
                closeRequest = true;
-               if (Context) {
-                       lws_cancel_service(Context);
-               }
 
                MSF_ERR("wsi destroyed with no communication");
                if (onErrorListener) {
index 69b3762..8322294 100755 (executable)
@@ -30,8 +30,13 @@ Clients::Clients(Channel *channel)
 
 Client Clients::get(string clientId)
 {
-       Client cl = clients.find(clientId)->second;
-       return cl;
+       if (clients.find(clientId) != clients.end()) {
+               Client cl = clients.find(clientId)->second;
+               return cl;
+       } else {
+               Client empty;
+               return empty;
+       }
 }
 
 Client* Clients::getHost()