From: Michal Kolodziej Date: Mon, 19 Sep 2016 14:41:39 +0000 (+0200) Subject: [Iotcon] Fixed wrong resource release in 3 functions X-Git-Tag: submit/tizen/20160920.235405~7^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=e84a6a51775da07db908d1ca7cc07cefeca6398d;p=platform%2Fcore%2Fapi%2Fwebapi-plugins.git [Iotcon] Fixed wrong resource release in 3 functions [Details] Fixed resource release in ClientFindResource (was creating new thread without locks), ClientFindDeviceInfo and ClientFindPlatformInfo (in both cases there is a possibility of multicast, and shared resources were released on first callback) Change-Id: Id8295a36f2b72a0d8f7af2d07270c8229f2412d9 Signed-off-by: Michal Kolodziej --- diff --git a/src/iotcon/iotcon_instance.cc b/src/iotcon/iotcon_instance.cc index 057c7a55..6f12ded7 100644 --- a/src/iotcon/iotcon_instance.cc +++ b/src/iotcon/iotcon_instance.cc @@ -1163,15 +1163,21 @@ bool IotconInstance::ResourceFoundCallback(iotcon_remote_resource_h resource, return IOTCON_FUNC_STOP; } - auto ret = IotconUtils::ConvertIotconError(result); - if (!ret) { - data->fun(ret, picojson::value{}); - return IOTCON_FUNC_STOP; + switch (result) { + case IOTCON_ERROR_NONE: + break; + case IOTCON_ERROR_TIMEOUT: + delete data; + return IOTCON_FUNC_STOP; + default: + auto ret = IotconUtils::ConvertIotconError(result); + data->fun(ret, picojson::value{}); + return IOTCON_FUNC_STOP; } picojson::value json_result = picojson::value(picojson::object()); - ret = IotconUtils::RemoteResourceToJson(resource, &(json_result.get())); + auto ret = IotconUtils::RemoteResourceToJson(resource, &(json_result.get())); if (!ret) { data->fun(ret, picojson::value{}); return IOTCON_FUNC_STOP; @@ -1237,20 +1243,6 @@ common::TizenResult IotconInstance::ClientFindResource(const picojson::object& a if (!result) { delete data; LogAndReturnTizenError(result); - } else { - int timeout = 60; //default value set much bigger than default value for iotcon = 30s - auto result = IotconUtils::ConvertIotconError(iotcon_get_timeout(&timeout)); - if (!result) { - LoggerE("iotcon_get_timeout - function call failed, using default value %d", timeout); - } else { - timeout = timeout + 1; //add one extra second to prevent too fast delete - } - // adding listener to delete data, when find would be finished - std::thread([data, timeout]() { - std::this_thread::sleep_for(std::chrono::seconds(timeout)); - LoggerD("Deleting resource find data: %p", data); - delete data; - }).detach(); } return common::TizenSuccess(); @@ -1333,14 +1325,18 @@ bool IotconDeviceInfoCb(iotcon_device_info_h device_info, picojson::value v{picojson::object{}}; common::TizenResult ret = common::TizenSuccess(); - if (IOTCON_ERROR_NONE != result) { - ret = IotconUtils::ConvertIotconError(result); - } else { - ret = IotconUtils::DeviceInfoToJson(device_info,&v.get()); + switch (result) { + case IOTCON_ERROR_NONE: + ret = IotconUtils::DeviceInfoToJson(device_info,&v.get()); + break; + case IOTCON_ERROR_TIMEOUT: + delete data; + return IOTCON_FUNC_STOP; + default: + ret = IotconUtils::ConvertIotconError(result); } data->fun(ret, v); - delete data; return IOTCON_FUNC_CONTINUE; } @@ -1404,14 +1400,18 @@ bool IotconPlatformInfoCb(iotcon_platform_info_h platform_info, picojson::value v{picojson::object{}}; common::TizenResult ret = common::TizenSuccess(); - if (IOTCON_ERROR_NONE != result) { - ret = IotconUtils::ConvertIotconError(result); - } else { - ret = IotconUtils::PlatformInfoToJson(platform_info,&v.get()); + switch (result) { + case IOTCON_ERROR_NONE: + ret = IotconUtils::PlatformInfoToJson(platform_info,&v.get()); + break; + case IOTCON_ERROR_TIMEOUT: + delete data; + return IOTCON_FUNC_STOP; + default: + ret = IotconUtils::ConvertIotconError(result); } data->fun(ret, v); - delete data; return IOTCON_FUNC_CONTINUE; }