diff options
author | Jooseok Park <jooseok.park@samsung.com> | 2017-02-10 13:43:53 +0900 |
---|---|---|
committer | Jooseok Park <jooseok.park@samsung.com> | 2017-02-10 16:43:57 +0900 |
commit | c7bfc45540aef33cc25c66f97cc721db6ef3013a (patch) | |
tree | b3b7d057144e5a19fddd02c3b9e75b7450c32843 | |
parent | b627062795f948178ea5941c9db85f1e8acccf91 (diff) | |
download | iotcon-c7bfc45540aef33cc25c66f97cc721db6ef3013a.tar.gz iotcon-c7bfc45540aef33cc25c66f97cc721db6ef3013a.tar.bz2 iotcon-c7bfc45540aef33cc25c66f97cc721db6ef3013a.zip |
Fix the memory leaksubmit/tizen/20170210.080005accepted/tizen/wearable/20170214.010413accepted/tizen/tv/20170214.010359accepted/tizen/mobile/20170214.010340accepted/tizen/ivi/20170214.010443accepted/tizen/common/20170210.170610
- fix memory leak for platform info
- fix the memory leak for uri
- fix memory leak for representation payload
- fix memory leak for provisioning data
Change-Id: Id6be4fe2a064575cb615a361ac877feff1d8c729
-rw-r--r-- | src/ic-ioty-convert.c | 10 | ||||
-rw-r--r-- | src/ic-ioty-convert.h | 2 | ||||
-rw-r--r-- | src/ic-ioty.c | 144 | ||||
-rw-r--r-- | src/ic-provisioning-struct.c | 20 | ||||
-rw-r--r-- | src/ic-utils.c | 86 | ||||
-rw-r--r-- | src/ic-utils.h | 2 |
6 files changed, 136 insertions, 128 deletions
diff --git a/src/ic-ioty-convert.c b/src/ic-ioty-convert.c index 55dc40d..ccc50fa 100644 --- a/src/ic-ioty-convert.c +++ b/src/ic-ioty-convert.c @@ -510,7 +510,7 @@ static int _icl_ioty_fill_oic_rep_payload_value(OCRepPayload *payload, } int ic_ioty_convert_representation(iotcon_representation_h repr, - OCPayload **payload) + OCRepPayload **payload) { FN_CALL; int ret; @@ -526,7 +526,7 @@ int ic_ioty_convert_representation(iotcon_representation_h repr, } if (NULL == repr) { - *payload = (OCPayload *)repr_payload; + *payload = repr_payload; return IOTCON_ERROR_NONE; } @@ -561,18 +561,18 @@ int ic_ioty_convert_representation(iotcon_representation_h repr, /* children */ cur = repr_payload; for (c = repr->children; c; c = c->next) { - OCPayload *child = NULL; + OCRepPayload *child = NULL; ret = ic_ioty_convert_representation(c->data, &child); if (IOTCON_ERROR_NONE != ret) { ERR("ic_ioty_convert_representation() Fail(%d)", ret); OCRepPayloadDestroy(repr_payload); return IOTCON_ERROR_IOTIVITY; } - cur->next = (OCRepPayload *)child; + cur->next = child; cur = cur->next; } - *payload = (OCPayload *)repr_payload; + *payload = repr_payload; return IOTCON_ERROR_NONE; } diff --git a/src/ic-ioty-convert.h b/src/ic-ioty-convert.h index cad3d0f..4736c23 100644 --- a/src/ic-ioty-convert.h +++ b/src/ic-ioty-convert.h @@ -32,7 +32,7 @@ int ic_ioty_convert_host_address(const char *host_address, uint8_t ic_ioty_convert_policies(uint8_t policies); int ic_ioty_convert_representation(iotcon_representation_h repr, - OCPayload **payload); + OCRepPayload **payload); int ic_ioty_convert_header_options(iotcon_options_h options, OCHeaderOption dest[], int dest_size); diff --git a/src/ic-ioty.c b/src/ic-ioty.c index 15dffe9..8408383 100644 --- a/src/ic-ioty.c +++ b/src/ic-ioty.c @@ -23,6 +23,8 @@ #include <ocstack.h> #include <ocpayload.h> #include <pinoxmcommon.h> +#include <system_info.h> +#include <vconf.h> #include "iotcon.h" #include "ic.h" @@ -46,11 +48,18 @@ #include "ic-ioty-ocprocess.h" #include "ic-cbor.h" + typedef struct { iotcon_generated_pin_cb cb; void *user_data; } icl_generated_pin_cb_container_s; +static const char *IC_SYSTEM_INFO_PLATFORM_VERSION = "http://tizen.org/feature/platform.version"; +static const char *IC_SYSTEM_INFO_MANUF_NAME = "http://tizen.org/system/manufacturer"; +static const char *IC_SYSTEM_INFO_MODEL_NAME = "http://tizen.org/system/model_name"; +static const char *IC_SYSTEM_INFO_BUILD_STRING = "http://tizen.org/system/build.string"; +static const char *IC_SYSTEM_INFO_TIZEN_ID = "http://tizen.org/system/tizenid"; + static bool icl_state; static bool icl_is_set_generated_pin_cb; static char icl_svr_db_file[PATH_MAX]; @@ -458,15 +467,14 @@ int icl_ioty_find_resource(const char *host_address, SECURE_DBG("full_uri:[%s], oic_conn_type:[0x%x]", full_uri, oic_conn_type); ret = OCDoResource(&handle, OC_REST_DISCOVER, full_uri, NULL, NULL, oic_conn_type, OC_LOW_QOS, &cbdata, NULL, 0); + free(full_uri); icl_ioty_mutex_unlock(); if (OC_STACK_OK != ret) { ERR("OCDoResource(DISCOVER) Fail(%d)", ret); _icl_ioty_free_cb_data(cb_data); - free(full_uri); return ic_ioty_parse_oic_error(ret); } - free(full_uri); cb_data->handle = handle; DBG("handle [%p], cb [%p]", cb_data->handle, cb_data->cb); @@ -548,12 +556,12 @@ int icl_ioty_find_device_info(const char *host_address, SECURE_DBG("full_uri:[%s], oic_conn_type:[0x%x]", full_uri, oic_conn_type); ret = OCDoResource(&handle, OC_REST_DISCOVER, full_uri, NULL, NULL, oic_conn_type, OC_LOW_QOS, &cbdata, NULL, 0); + free(full_uri); icl_ioty_mutex_unlock(); if (OC_STACK_OK != ret) { ERR("OCDoResource(DISCOVER) Fail(%d)", ret); _icl_ioty_free_cb_data(cb_data); - free(full_uri); return ic_ioty_parse_oic_error(ret); } @@ -637,12 +645,12 @@ int icl_ioty_find_platform_info(const char *host_address, SECURE_DBG("full_uri:[%s], oic_conn_type:[0x%x]", full_uri, oic_conn_type); ret = OCDoResource(&handle, OC_REST_DISCOVER, full_uri, NULL, NULL, oic_conn_type, OC_LOW_QOS, &cbdata, NULL, 0); + free(full_uri); icl_ioty_mutex_unlock(); if (OC_STACK_OK != ret) { ERR("OCDoResource(DISCOVER) Fail(%d)", ret); _icl_ioty_free_cb_data(cb_data); - free(full_uri); return ic_ioty_parse_oic_error(ret); } @@ -687,34 +695,104 @@ int icl_ioty_set_device_info(const char *device_name) return IOTCON_ERROR_NONE; } +static int _icl_ioty_get_platform_info(OCPlatformInfo *platform_info) +{ + int ret; + char *tizen_id = NULL; + char *device_name = NULL; + char platform_id[1024]; + + RETV_IF(NULL == platform_info, IOTCON_ERROR_INVALID_PARAMETER); + + device_name = vconf_get_str(VCONFKEY_SETAPPL_DEVICE_NAME_STR); + WARN_IF(device_name == NULL, "vconf_get_str() Fail"); + + ret = system_info_get_platform_string(IC_SYSTEM_INFO_TIZEN_ID, &tizen_id); + WARN_IF(SYSTEM_INFO_ERROR_NONE != ret, "system_info_get_platform_string() Fail(%d)", ret); + + snprintf(platform_id, sizeof(platform_id), "%s(%s)", IC_SAFE_STR(device_name), IC_SAFE_STR(tizen_id)); + + free(device_name); + free(tizen_id); + SECURE_DBG("platform_id: %s", platform_id); + + /* Mandatory (oic.wk.p) */ + platform_info->platformID = strdup(platform_id); + + /* Mandatory (oic.wk.p) */ + ret = system_info_get_platform_string(IC_SYSTEM_INFO_MANUF_NAME, + &platform_info->manufacturerName); + if (SYSTEM_INFO_ERROR_NONE != ret) { + ERR("system_info_get_platform_string(manufacturer) Fail(%d)", ret); + free(platform_info->platformID); + return IOTCON_ERROR_SYSTEM; + } + + ret = system_info_get_platform_string(IC_SYSTEM_INFO_MODEL_NAME, + &platform_info->modelNumber); + if (SYSTEM_INFO_ERROR_NONE != ret) + WARN("system_info_get_platform_string(model_name) Fail(%d)", ret); + + ret = system_info_get_platform_string(IC_SYSTEM_INFO_PLATFORM_VERSION, + &platform_info->platformVersion); + if (SYSTEM_INFO_ERROR_NONE != ret) + WARN("system_info_get_platform_string(platform_version) Fail(%d)", ret); + + ret = system_info_get_platform_string(IC_SYSTEM_INFO_BUILD_STRING, + &platform_info->firmwareVersion); + if (SYSTEM_INFO_ERROR_NONE != ret) + WARN("system_info_get_platform_string(build_string) Fail(%d)", ret); + + /* platform_info.manufacturerUrl */ + /* platform_info.dateOfManufacture */ + /* platform_info.operatingSystemVersion */ + /* platform_info.hardwareVersion */ + /* platform_info.supportUrl */ + /* platform_info.systemTime */ + + return IOTCON_ERROR_NONE; +} + +static void _icl_ioty_free_platform_info(OCPlatformInfo *platform_info) +{ + RET_IF(NULL == platform_info); + + free(platform_info->platformID); + free(platform_info->manufacturerName); + free(platform_info->manufacturerUrl); + free(platform_info->modelNumber); + free(platform_info->dateOfManufacture); + free(platform_info->platformVersion); + free(platform_info->operatingSystemVersion); + free(platform_info->hardwareVersion); + free(platform_info->firmwareVersion); + free(platform_info->supportUrl); + free(platform_info->systemTime); +} + int icl_ioty_set_platform_info() { int ret; OCPlatformInfo platform_info = {0}; - ret = ic_utils_get_platform_info(&platform_info); + ret = _icl_ioty_get_platform_info(&platform_info); if (IOTCON_ERROR_NONE != ret) { - ERR("ic_utils_get_platform_info() Fail(%d)", ret); + ERR("_icl_ioty_get_platform_info() Fail(%d)", ret); return ret; } - ret = icl_ioty_mutex_lock(); - if (IOTCON_ERROR_NONE != ret) { - ERR("icl_ioty_mutex_lock() Fail(%d)", ret); - ic_utils_free_platform_info(&platform_info); - return ret; - } + ic_utils_mutex_lock(IC_UTILS_MUTEX_IOTY); ret = OCSetPlatformInfo(platform_info); - icl_ioty_mutex_unlock(); - + _icl_ioty_free_platform_info(&platform_info); + ic_utils_mutex_unlock(IC_UTILS_MUTEX_IOTY); if (OC_STACK_OK != ret) { ERR("OCSetPlatformInfo() Fail(%d)", ret); - ic_utils_free_platform_info(&platform_info); - return ic_ioty_parse_oic_error(ret); + ret = ic_ioty_parse_oic_error(ret); + } else { + ret = IOTCON_ERROR_NONE; } - ic_utils_free_platform_info(&platform_info); - return IOTCON_ERROR_NONE; + return ret; } int icl_ioty_add_presence_cb(const char *host_address, @@ -939,19 +1017,16 @@ static int _icl_ioty_remote_resource_observe(iotcon_remote_resource_h resource, SECURE_DBG("uri:[%s], oic_conn_type:[0x%x]", uri, oic_conn_type); ret = OCDoResource(obs_handle, method, uri, &dev_addr, NULL, oic_conn_type, OC_HIGH_QOS, &cbdata, oic_options_ptr, options_size); + free(uri); icl_ioty_mutex_unlock(); if (OC_STACK_OK != ret) { ERR("OCDoResource(OBSERVE:%d) Fail(%d)", method, ret); _icl_ioty_free_observe_container(cb_container); - free(uri); return IOTCON_ERROR_IOTIVITY; } - free(uri); - return IOTCON_ERROR_NONE; - } int icl_ioty_remote_resource_observe_register( @@ -1084,7 +1159,7 @@ static int _icl_ioty_remote_resource_crud( OCConnectivityType oic_conn_type; OCDevAddr dev_addr = {0}; OCMethod method; - OCPayload *payload = NULL; + OCRepPayload *payload = NULL; RETV_IF(NULL == resource, IOTCON_ERROR_INVALID_PARAMETER); RETV_IF(NULL == cb, IOTCON_ERROR_INVALID_PARAMETER); @@ -1131,7 +1206,7 @@ static int _icl_ioty_remote_resource_crud( sizeof(oic_options)/sizeof(oic_options[0])); if (IOTCON_ERROR_NONE != ret) { ERR("ic_ioty_convert_header_options() Fail(%d)", ret); - OCRepPayloadDestroy((OCRepPayload*)payload); + OCRepPayloadDestroy(payload); free(uri); return ret; } @@ -1142,7 +1217,7 @@ static int _icl_ioty_remote_resource_crud( cb_container = calloc(1, sizeof(icl_response_container_s)); if (NULL == cb_container) { ERR("calloc() Fail(%d)", errno); - OCRepPayloadDestroy((OCRepPayload*)payload); + OCRepPayloadDestroy(payload); free(uri); return IOTCON_ERROR_OUT_OF_MEMORY; } @@ -1164,18 +1239,18 @@ static int _icl_ioty_remote_resource_crud( return ret; } SECURE_DBG("uri:[%s], oic_conn_type:[0x%x]", uri, oic_conn_type); - ret = OCDoResource(NULL, method, uri, &dev_addr, payload, oic_conn_type, + ret = OCDoResource(NULL, method, uri, &dev_addr, (OCPayload *)payload, oic_conn_type, OC_HIGH_QOS, &cbdata, oic_options_ptr, options_size); + free(uri); icl_ioty_mutex_unlock(); if (OC_STACK_OK != ret) { ERR("OCDoResource(CRUD:%d) Fail(%d)", method, ret); - free(uri); + OCRepPayloadDestroy(payload); _icl_ioty_free_response_container(cb_container); return ic_ioty_parse_oic_error(ret); } - free(uri); icl_get_timeout(&timeout); cb_container->timeout = g_timeout_add_seconds(timeout, _icl_ioty_response_timeout, cb_container); @@ -1800,7 +1875,7 @@ int icl_ioty_resource_notify(iotcon_resource_h resource, iotcon_representation_h return IOTCON_ERROR_NONE; } - ret = ic_ioty_convert_representation(repr, (OCPayload **)&payload); + ret = ic_ioty_convert_representation(repr, &payload); if (IOTCON_ERROR_NONE != ret) { ERR("ic_ioty_convert_representation() Fail(%d)", ret); return ret; @@ -1813,10 +1888,12 @@ int icl_ioty_resource_notify(iotcon_resource_h resource, iotcon_representation_h ERR("icl_ioty_mutex_lock() Fail(%d)", ret); return ret; } - if (payload) + if (payload) { ret = OCNotifyListOfObservers(resource->res_handle, obs_ids, obs_length, payload, oc_qos); - else + OCRepPayloadDestroy(payload); + } else { ret = OCNotifyAllObservers(resource->res_handle, oc_qos); + } icl_ioty_mutex_unlock(); if (OC_STACK_NO_OBSERVERS == ret) { @@ -2011,6 +2088,7 @@ int icl_ioty_response_send(iotcon_response_h response_handle) FN_CALL; int ret; OCEntityHandlerResponse response = {0}; + OCRepPayload *payload = NULL; RETV_IF(NULL == response_handle, IOTCON_ERROR_INVALID_PARAMETER); @@ -2029,7 +2107,8 @@ int icl_ioty_response_send(iotcon_response_h response_handle) } - ic_ioty_convert_representation(response_handle->repr, &(response.payload)); + ic_ioty_convert_representation(response_handle->repr, &payload); + response.payload = (OCPayload*)payload; /* related to block transfer */ response.persistentBufferFlag = 0; @@ -2040,6 +2119,7 @@ int icl_ioty_response_send(iotcon_response_h response_handle) return ret; } ret = OCDoResponse(&response); + OCRepPayloadDestroy(payload); icl_ioty_mutex_unlock(); if (OC_STACK_OK != ret) { diff --git a/src/ic-provisioning-struct.c b/src/ic-provisioning-struct.c index ef83418..84e75c6 100644 --- a/src/ic-provisioning-struct.c +++ b/src/ic-provisioning-struct.c @@ -178,7 +178,7 @@ OCProvisionDev_t* icl_provisioning_oic_device_clone(OCProvisionDev_t *src) clone->pstat->sm = calloc(1, sizeof(OicSecDpom_t)); if (NULL == clone->pstat->sm) { ERR("calloc() Fail(%d)", errno); - return NULL; + goto OUT; } memcpy(clone->pstat->sm, src->pstat->sm, sizeof(OicSecDpom_t)); } @@ -189,7 +189,7 @@ OCProvisionDev_t* icl_provisioning_oic_device_clone(OCProvisionDev_t *src) clone->doxm->oxmType = calloc(1, sizeof(OicUrn_t)); if (NULL == clone->doxm->oxmType) { ERR("calloc() Fail(%d)", errno); - return NULL; + goto OUT; } memcpy(clone->doxm->oxmType, src->doxm->oxmType, sizeof(OicUrn_t)); } @@ -197,13 +197,26 @@ OCProvisionDev_t* icl_provisioning_oic_device_clone(OCProvisionDev_t *src) clone->doxm->oxm = calloc(1, sizeof(OicSecOxm_t)); if (NULL == clone->doxm->oxm) { ERR("calloc() Fail(%d)", errno); - return NULL; + goto OUT; } memcpy(clone->doxm->oxm, src->doxm->oxm, sizeof(OicSecOxm_t)); } } return clone; + +OUT: + if (clone->pstat) { + free(clone->pstat->sm); + free(clone->pstat); + } + if (clone->doxm) { + free(clone->doxm->oxmType); + free(clone->doxm->oxm); + free(clone->doxm); + } + free(clone); + return NULL; } @@ -586,6 +599,7 @@ int icl_provisioning_acl_set_all_subject(iotcon_provisioning_acl_h acl) dev->doxm = calloc(1, sizeof(OicSecDoxm_t)); if (NULL == dev->doxm) { ERR("calloc() Fail(%d)", errno); + free(dev); return IOTCON_ERROR_OUT_OF_MEMORY; } diff --git a/src/ic-utils.c b/src/ic-utils.c index 9f1a1fd..781c694 100644 --- a/src/ic-utils.c +++ b/src/ic-utils.c @@ -22,7 +22,6 @@ #include <pthread.h> #include <glib.h> #include <system_info.h> -#include <vconf.h> #include <cynara-client.h> #include <cynara-error.h> @@ -48,12 +47,6 @@ static const char *IC_PRIV_FILE_INTERNET = "/usr/share/iotcon/iotcon-internet"; static const char *IC_PRIVILEGE_INTERNET = "http://tizen.org/privilege/internet"; static const char *IC_PRIVILEGE_NETWORK_GET = "http://tizen.org/privilege/network.get"; -static const char *IC_SYSTEM_INFO_PLATFORM_VERSION = "http://tizen.org/feature/platform.version"; -static const char *IC_SYSTEM_INFO_MANUF_NAME = "http://tizen.org/system/manufacturer"; -static const char *IC_SYSTEM_INFO_MODEL_NAME = "http://tizen.org/system/model_name"; -static const char *IC_SYSTEM_INFO_BUILD_STRING = "http://tizen.org/system/build.string"; -static const char *IC_SYSTEM_INFO_TIZEN_ID = "http://tizen.org/system/tizenid"; - static pthread_mutex_t ic_utils_mutex_init = PTHREAD_MUTEX_INITIALIZER; static pthread_mutex_t ic_utils_mutex_ioty = PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP; static pthread_mutex_t ic_utils_mutex_polling = PTHREAD_MUTEX_INITIALIZER; @@ -86,7 +79,7 @@ bool ic_utils_check_permission(int permssion) char smack_label[SMACK_LABEL_LEN + 1] = {0}; char uid[10]; FILE *fd; - cynara *cynara_h; + cynara *cynara_h = NULL; ret = cynara_initialize(&cynara_h, NULL); if (CYNARA_API_SUCCESS != ret) { @@ -150,83 +143,6 @@ bool ic_utils_check_ocf_feature() #endif } -void ic_utils_free_platform_info(OCPlatformInfo *platform_info) -{ - RET_IF(NULL == platform_info); - - free(platform_info->manufacturerName); - free(platform_info->manufacturerUrl); - free(platform_info->modelNumber); - free(platform_info->dateOfManufacture); - free(platform_info->platformVersion); - free(platform_info->operatingSystemVersion); - free(platform_info->hardwareVersion); - free(platform_info->firmwareVersion); - free(platform_info->supportUrl); - free(platform_info->systemTime); -} - -int ic_utils_get_platform_info(OCPlatformInfo *platform_info) -{ - int ret; - char *tizen_id = NULL; - char *device_name = NULL; - char platform_id[1024]; - - RETV_IF(NULL == platform_info, IOTCON_ERROR_INVALID_PARAMETER); - - device_name = vconf_get_str(VCONFKEY_SETAPPL_DEVICE_NAME_STR); - WARN_IF(device_name == NULL, "vconf_get_str() Fail"); - - ret = system_info_get_platform_string(IC_SYSTEM_INFO_TIZEN_ID, &tizen_id); - WARN_IF(SYSTEM_INFO_ERROR_NONE != ret, "system_info_get_platform_string() Fail(%d)", ret); - - snprintf(platform_id, sizeof(platform_id), "%s(%s)", IC_SAFE_STR(device_name), IC_SAFE_STR(tizen_id)); - SECURE_DBG("platform_id: %s", platform_id); - - if (device_name) - free(device_name); - if (tizen_id) - free(tizen_id); - - /* Mandatory (oic.wk.p) */ - platform_info->platformID = strdup(platform_id); - - /* Mandatory (oic.wk.p) */ - ret = system_info_get_platform_string(IC_SYSTEM_INFO_MANUF_NAME, - &platform_info->manufacturerName); - if (SYSTEM_INFO_ERROR_NONE != ret) { - ERR("system_info_get_platform_string(manufacturer) Fail(%d)", ret); - ic_utils_free_platform_info(platform_info); - return IOTCON_ERROR_SYSTEM; - } - - ret = system_info_get_platform_string(IC_SYSTEM_INFO_MODEL_NAME, - &platform_info->modelNumber); - if (SYSTEM_INFO_ERROR_NONE != ret) - WARN("system_info_get_platform_string(model_name) Fail(%d)", ret); - - ret = system_info_get_platform_string(IC_SYSTEM_INFO_PLATFORM_VERSION, - &platform_info->platformVersion); - if (SYSTEM_INFO_ERROR_NONE != ret) - WARN("system_info_get_platform_string(platform_version) Fail(%d)", ret); - - ret = system_info_get_platform_string(IC_SYSTEM_INFO_BUILD_STRING, - &platform_info->firmwareVersion); - if (SYSTEM_INFO_ERROR_NONE != ret) - WARN("system_info_get_platform_string(build_string) Fail(%d)", ret); - - /* platform_info.manufacturerUrl */ - /* platform_info.dateOfManufacture */ - /* platform_info.operatingSystemVersion */ - /* platform_info.hardwareVersion */ - /* platform_info.supportUrl */ - /* platform_info.systemTime */ - - return IOTCON_ERROR_NONE; -} - - static inline pthread_mutex_t* _utils_mutex_get(int type) { pthread_mutex_t *mutex; diff --git a/src/ic-utils.h b/src/ic-utils.h index 20aba19..d49bebf 100644 --- a/src/ic-utils.h +++ b/src/ic-utils.h @@ -30,8 +30,6 @@ enum { char* ic_utils_strdup(const char *src); bool ic_utils_check_permission(int permssion); bool ic_utils_check_ocf_feature(); -int ic_utils_get_platform_info(OCPlatformInfo *platform_info); -void ic_utils_free_platform_info(OCPlatformInfo *platform_info); void ic_utils_mutex_lock(int type); void ic_utils_mutex_unlock(int type); |