From 3d0052610e10bc923baca09fc9e89e8625f99c68 Mon Sep 17 00:00:00 2001 From: "sung.goo.kim" Date: Fri, 20 Nov 2015 11:30:14 +0900 Subject: [PATCH] Fix internal logic Change-Id: I88803b42fb56e45d663048e646cf0f0a0822d717 --- daemon/icd-payload.c | 1 - lib/icl-list.c | 8 ++------ lib/icl-representation.c | 16 ++++------------ lib/icl-state.c | 19 +++++++++++-------- lib/icl-state.h | 1 - 5 files changed, 17 insertions(+), 28 deletions(-) diff --git a/daemon/icd-payload.c b/daemon/icd-payload.c index bdc2f06..e12d697 100644 --- a/daemon/icd-payload.c +++ b/daemon/icd-payload.c @@ -464,7 +464,6 @@ static void _icd_state_list_from_gvariant(GVariant *var, g_variant_iter_init(&state_iter, value); _icd_state_value_from_gvariant(repr, &state_iter); value_list->list = g_list_append(value_list->list, repr); - g_variant_iter_free(&state_iter); } while (g_variant_iter_loop(&iter, "v", &value)); } else if (g_variant_is_of_type(value, G_VARIANT_TYPE_ARRAY)) { diff --git a/lib/icl-list.c b/lib/icl-list.c index 6e8ef1e..0ece1f5 100644 --- a/lib/icl-list.c +++ b/lib/icl-list.c @@ -34,18 +34,14 @@ void icl_list_inc_ref_count(iotcon_list_h val) static bool _icl_list_dec_ref_count(iotcon_list_h val) { - bool ret; - RETV_IF(NULL == val, false); RETVM_IF(val->ref_count <= 0, false, "Invalid Count(%d)", val->ref_count); val->ref_count--; if (0 == val->ref_count) - ret = true; - else - ret = false; + return true; - return ret; + return false; } static int _icl_list_create(iotcon_type_e type, iotcon_list_h *ret_list) diff --git a/lib/icl-representation.c b/lib/icl-representation.c index a3c0d8d..eeba7ee 100644 --- a/lib/icl-representation.c +++ b/lib/icl-representation.c @@ -43,18 +43,14 @@ void icl_representation_inc_ref_count(iotcon_representation_h val) static bool _icl_representation_dec_ref_count(iotcon_representation_h val) { - bool ret; - - RETV_IF(NULL == val, -1); + RETV_IF(NULL == val, false); RETVM_IF(val->ref_count <= 0, false, "Invalid Count(%d)", val->ref_count); val->ref_count--; if (0 == val->ref_count) - ret = true; - else - ret = false; + return true; - return ret; + return false; } @@ -118,13 +114,9 @@ API int iotcon_representation_set_uri_path(iotcon_representation_h repr, const char *uri_path) { RETV_IF(NULL == repr, IOTCON_ERROR_INVALID_PARAMETER); + RETV_IF(NULL == uri_path, IOTCON_ERROR_INVALID_PARAMETER); free(repr->uri_path); - repr->uri_path = NULL; - - if (NULL == uri_path) - return IOTCON_ERROR_INVALID_PARAMETER; - repr->uri_path = strdup(uri_path); if (NULL == repr->uri_path) { ERR("strdup() Fail"); diff --git a/lib/icl-state.c b/lib/icl-state.c index 7618bd8..fce11e7 100644 --- a/lib/icl-state.c +++ b/lib/icl-state.c @@ -33,14 +33,16 @@ void icl_state_inc_ref_count(iotcon_state_h val) } -int icl_state_dec_ref_count(iotcon_state_h val) +static bool _icl_state_dec_ref_count(iotcon_state_h val) { - RETV_IF(NULL == val, -1); - RETVM_IF(val->ref_count <= 0, 0, "Invalid Count(%d)", val->ref_count); + RETV_IF(NULL == val, false); + RETVM_IF(val->ref_count <= 0, false, "Invalid Count(%d)", val->ref_count); val->ref_count--; + if (0 == val->ref_count) + return true; - return val->ref_count; + return false; } @@ -71,10 +73,11 @@ API void iotcon_state_destroy(iotcon_state_h state) { RET_IF(NULL == state); - if (0 == icl_state_dec_ref_count(state)) { - g_hash_table_destroy(state->hash_table); - free(state); - } + if (false == _icl_state_dec_ref_count(state)) + return; + + g_hash_table_destroy(state->hash_table); + free(state); } API int iotcon_state_clone(iotcon_state_h state, iotcon_state_h *state_clone) diff --git a/lib/icl-state.h b/lib/icl-state.h index 0cfa0c1..6e2aad5 100644 --- a/lib/icl-state.h +++ b/lib/icl-state.h @@ -20,7 +20,6 @@ #include "icl-representation.h" void icl_state_inc_ref_count(iotcon_state_h val); -int icl_state_dec_ref_count(iotcon_state_h val); int icl_state_del_value(iotcon_state_h state, const char *key); -- 2.34.1