Fixed crash issue on unset_listener_cb() is called right after publish() 50/108150/2
authorkmook <kmook.choi@samsung.com>
Tue, 3 Jan 2017 06:56:17 +0000 (15:56 +0900)
committerKyoung-Mook Choi <kmook.choi@samsung.com>
Tue, 3 Jan 2017 06:56:58 +0000 (22:56 -0800)
Change-Id: I157ca47286b848d9c6be5bb6b2137f89f91d0aeb
Signed-off-by: kmook <kmook.choi@samsung.com>
daemon/service_provider/RemoteAppControlServiceProvider.cpp

index 0375bc3..9ecd7ad 100755 (executable)
@@ -948,7 +948,8 @@ static void __on_response(iotcon_remote_resource_h resource, iotcon_error_e err,
                if (appcontrol_result == IOTCON_ERROR_NONE) {
                        payload.set(NULL, CONV_JSON_APP_CONTROL_RESULT, resultStr.c_str());
                }
-               result.set(NULL, CONV_JSON_DESCRIPTION, cb_info.requestObj->getDescription());
+               description = cb_info.requestObj->getDescription();
+               result.set(NULL, CONV_JSON_DESCRIPTION, description);
                result.set(NULL, CONV_JSON_PAYLOAD, payload);
 
                cb_info.requestObj->publish(CONV_ERROR_NONE, result, 0, NULL);
@@ -975,7 +976,8 @@ CATCH:
                        payload.set(NULL, CONV_JSON_APP_CONTROL_REQUEST, appctl_request_char);
                }
 
-               result.set(NULL, CONV_JSON_DESCRIPTION, cb_info.requestObj->getDescription());
+               description = cb_info.requestObj->getDescription();
+               result.set(NULL, CONV_JSON_DESCRIPTION, description);
                result.set(NULL, CONV_JSON_PAYLOAD, payload);
 
                cb_info.requestObj->publish(CONV_ERROR_INVALID_OPERATION, result, 0, NULL);
@@ -1058,6 +1060,16 @@ int conv::RemoteAppControlServiceProvider::registerRequest(Request* requestObj)
        switch (requestObj->getType()) {
        case REQ_SUBSCRIBE:
                if (svcInfo->registeredRequest != NULL) {
+                       for (std::map<int, response_cb_info_s>::iterator it = response_cb_map.begin(); it != response_cb_map.end(); ++it) {
+                               if (((response_cb_info_s)it->second).requestObj == svcInfo->registeredRequest) {
+                                       response_cb_info_s cbInfo;
+                                       cbInfo.req_id = ((response_cb_info_s)it->second).req_id;
+                                       cbInfo.requestObj = requestObj;
+
+                                       it->second = cbInfo;
+                               }
+                       }
+
                        delete svcInfo->registeredRequest;
                }
                svcInfo->registeredRequest = requestObj;
@@ -1065,6 +1077,17 @@ int conv::RemoteAppControlServiceProvider::registerRequest(Request* requestObj)
                _D("subscribe requested");
                break;
        case REQ_UNSUBSCRIBE:
+               for (std::map<int, response_cb_info_s>::iterator it = response_cb_map.begin(); it != response_cb_map.end(); ++it) {
+                       if (((response_cb_info_s)it->second).requestObj == svcInfo->registeredRequest) {
+                               response_cb_info_s cbInfo;
+                               cbInfo.req_id = ((response_cb_info_s)it->second).req_id;
+                               cbInfo.requestObj = NULL;
+
+                               it->second = cbInfo;
+                       }
+               }
+
+               delete svcInfo->registeredRequest;
                svcInfo->registeredRequest = NULL;
                requestObj->reply(CONV_ERROR_NONE);
                delete requestObj;