From 2d419fd489e23adeb3b885dd039a44772dff695c Mon Sep 17 00:00:00 2001 From: youngman Date: Thu, 3 Dec 2015 12:09:02 +0900 Subject: [PATCH] fix the problem when structures are destoried, repeatedly Change-Id: I2f7983126f7864fe9945b6a8d82cf647f3da7c50 Signed-off-by: youngman --- daemon/icd-ioty-ocprocess.c | 13 +++++++++---- lib/icl-device.c | 2 ++ lib/icl-lite-resource.c | 1 + lib/icl-presence.c | 1 + lib/icl-remote-resource-caching.c | 1 + lib/icl-remote-resource-crud.c | 3 +++ lib/icl-remote-resource-monitoring.c | 1 + lib/icl-remote-resource.c | 1 + lib/icl-resource.c | 2 ++ 9 files changed, 21 insertions(+), 4 deletions(-) diff --git a/daemon/icd-ioty-ocprocess.c b/daemon/icd-ioty-ocprocess.c index 960a51d..bfa8804 100644 --- a/daemon/icd-ioty-ocprocess.c +++ b/daemon/icd-ioty-ocprocess.c @@ -785,14 +785,19 @@ OCStackApplicationResult icd_ioty_ocprocess_observe_cb(void *ctx, GVariantBuilder *options; struct icd_observe_context *observe_ctx; icd_sig_ctx_s *sig_context = ctx; + OCStackApplicationResult cb_result; RETV_IF(NULL == ctx, OC_STACK_KEEP_TRANSACTION); + RETV_IF(NULL == resp, OC_STACK_KEEP_TRANSACTION); + + cb_result = (OC_OBSERVE_DEREGISTER == resp->sequenceNumber)? + OC_STACK_DELETE_TRANSACTION:OC_STACK_KEEP_TRANSACTION; if (NULL == resp->payload) { ERR("payload is empty"); _observe_cb_response_error(sig_context->bus_name, sig_context->signal_number, IOTCON_ERROR_IOTIVITY); - return OC_STACK_KEEP_TRANSACTION; + return cb_result; } observe_ctx = calloc(1, sizeof(struct icd_observe_context)); @@ -800,7 +805,7 @@ OCStackApplicationResult icd_ioty_ocprocess_observe_cb(void *ctx, ERR("calloc() Fail(%d)", errno); _observe_cb_response_error(sig_context->bus_name, sig_context->signal_number, IOTCON_ERROR_OUT_OF_MEMORY); - return OC_STACK_KEEP_TRANSACTION; + return cb_result; } res = _ocprocess_parse_oic_result(resp->result); @@ -824,13 +829,13 @@ OCStackApplicationResult icd_ioty_ocprocess_observe_cb(void *ctx, g_variant_unref(observe_ctx->payload); g_variant_builder_unref(observe_ctx->options); free(observe_ctx); - return OC_STACK_KEEP_TRANSACTION; + return cb_result; } /* DO NOT FREE sig_context. It MUST be freed in the ocstack */ /* DO NOT FREE observe_ctx. It MUST be freed in the _worker_observe_cb func */ - return OC_STACK_KEEP_TRANSACTION; + return cb_result; } diff --git a/lib/icl-device.c b/lib/icl-device.c index 50238f2..4a12c24 100644 --- a/lib/icl-device.c +++ b/lib/icl-device.c @@ -125,6 +125,7 @@ static gboolean _icl_timeout_get_device_info(gpointer p) cb_container->cb(&info, IOTCON_ERROR_TIMEOUT, cb_container->user_data); icl_dbus_unsubscribe_signal(cb_container->id); + cb_container->id = 0; return G_SOURCE_REMOVE; } @@ -304,6 +305,7 @@ static gboolean _icl_timeout_get_platform_info(gpointer p) cb_container->cb(&info, IOTCON_ERROR_TIMEOUT, cb_container->user_data); icl_dbus_unsubscribe_signal(cb_container->id); + cb_container->id = 0; return G_SOURCE_REMOVE; } diff --git a/lib/icl-lite-resource.c b/lib/icl-lite-resource.c index 8233a95..beb71a0 100644 --- a/lib/icl-lite-resource.c +++ b/lib/icl-lite-resource.c @@ -385,6 +385,7 @@ API int iotcon_lite_resource_destroy(iotcon_lite_resource_h resource) resource->handle = 0; icl_dbus_unsubscribe_signal(resource->sub_id); + resource->sub_id = 0; return IOTCON_ERROR_NONE; } diff --git a/lib/icl-presence.c b/lib/icl-presence.c index 8ae81c9..8b9dab2 100644 --- a/lib/icl-presence.c +++ b/lib/icl-presence.c @@ -281,6 +281,7 @@ API int iotcon_remove_presence_cb(iotcon_presence_h presence) presence->handle = 0; icl_dbus_unsubscribe_signal(presence->sub_id); + presence->sub_id = 0; return IOTCON_ERROR_NONE; } diff --git a/lib/icl-remote-resource-caching.c b/lib/icl-remote-resource-caching.c index ba9fe32..e39380d 100644 --- a/lib/icl-remote-resource-caching.c +++ b/lib/icl-remote-resource-caching.c @@ -180,6 +180,7 @@ API int iotcon_remote_resource_stop_caching(iotcon_remote_resource_h resource) } icl_dbus_unsubscribe_signal(resource->caching_sub_id); + resource->caching_sub_id = 0; return IOTCON_ERROR_NONE; } diff --git a/lib/icl-remote-resource-crud.c b/lib/icl-remote-resource-crud.c index b97329c..0724b00 100644 --- a/lib/icl-remote-resource-crud.c +++ b/lib/icl-remote-resource-crud.c @@ -550,8 +550,11 @@ API int iotcon_remote_resource_observe_deregister(iotcon_remote_resource_h resou ERR("iotcon-daemon Fail(%d)", ret); return icl_dbus_convert_daemon_error(ret); } + resource->observe_handle = 0; icl_dbus_unsubscribe_signal(resource->observe_sub_id); + resource->observe_sub_id = 0; + return IOTCON_ERROR_NONE; } diff --git a/lib/icl-remote-resource-monitoring.c b/lib/icl-remote-resource-monitoring.c index 600e8e7..5bdcd7c 100644 --- a/lib/icl-remote-resource-monitoring.c +++ b/lib/icl-remote-resource-monitoring.c @@ -156,6 +156,7 @@ API int iotcon_remote_resource_stop_monitoring(iotcon_remote_resource_h resource } icl_dbus_unsubscribe_signal(resource->monitoring_sub_id); + resource->monitoring_sub_id = 0; return IOTCON_ERROR_NONE; } diff --git a/lib/icl-remote-resource.c b/lib/icl-remote-resource.c index 5bb0176..0337060 100644 --- a/lib/icl-remote-resource.c +++ b/lib/icl-remote-resource.c @@ -88,6 +88,7 @@ static gboolean _icl_timeout_find_resource(gpointer p) cb_container->cb(NULL, IOTCON_ERROR_TIMEOUT, cb_container->user_data); icl_dbus_unsubscribe_signal(cb_container->id); + cb_container->id = 0; return G_SOURCE_REMOVE; } diff --git a/lib/icl-resource.c b/lib/icl-resource.c index 2e54af5..b077a6c 100644 --- a/lib/icl-resource.c +++ b/lib/icl-resource.c @@ -265,7 +265,9 @@ API int iotcon_resource_destroy(iotcon_resource_h resource) return ret; } resource->handle = 0; + icl_dbus_unsubscribe_signal(resource->sub_id); + resource->sub_id = 0; return IOTCON_ERROR_NONE; } -- 2.7.4