Fix SVace warnings
[platform/core/connectivity/zigbee-manager.git] / zigbee-daemon / zigbee-lib / src / zblib_service.c
index 6d64f8c..681dc31 100644 (file)
@@ -114,17 +114,35 @@ static gboolean __zblib_service_init_plugin(ZigBeePlugin *plugin)
 static gboolean __zblib_service_unload_plugin(ZigBeePlugin *plugin)
 {
        const ZblibPluginDescriptor_t *descriptor = zblib_plugin_get_descriptor(plugin);
-       char *plugin_name = zblib_plugin_get_plugin_name(plugin);
+       char *plugin_name = NULL;
 
        zblib_check_null_ret_error("descriptor", descriptor, FALSE);
        zblib_check_null_ret_error("descriptor->unload", descriptor->unload, FALSE);
 
+       plugin_name = zblib_plugin_get_plugin_name(plugin);
+
        descriptor->unload(plugin);
        Z_LOGI("plugin(%s) unloaded!", plugin_name);
 
+       g_free(plugin_name);
+
        return TRUE;
 }
 
+static void __zblib_service_remove_request_table_iter(gpointer key,
+       gpointer value, gpointer user_data)
+{
+       ZigBeeServiceInterface *service_interface = (ZigBeeServiceInterface *)user_data;
+       gint request_id = (gint)key;
+
+       NOT_USED(value);
+
+       zblib_check_null_ret("service_interface", service_interface);
+
+       Z_LOGD("Removing request id [%d]", request_id);
+       zblib_request_free(service_interface, request_id);
+}
+
 ZigBeeService *zblib_service_new()
 {
        ZigBeeService *service;
@@ -150,6 +168,31 @@ void zblib_service_free(ZigBeeService *service)
 {
        zblib_check_null_ret("service", service);
 
+       if (service->request_table) {
+               GSList *interface_objs = NULL;
+               ZigBeeServiceInterface *service_interface = NULL;
+
+               interface_objs = service->interface_objs;
+               if (NULL == interface_objs) {
+                       Z_LOGE("interface_objs is NULL");
+               } else {
+                       while (interface_objs) {
+                               service_interface = (ZigBeeServiceInterface *)interface_objs->data;
+
+                               /* Remove left request */
+                               g_hash_table_foreach(service->request_table,
+                                               __zblib_service_remove_request_table_iter,
+                                               service_interface);
+
+                               /* Move to next service interface */
+                               interface_objs = g_slist_next(interface_objs);
+                       }
+                       g_hash_table_remove_all(service->request_table);
+                       g_hash_table_destroy(service->request_table);
+                       service->request_table = NULL;
+               }
+       }
+
        /* Free plug-ins */
        if (service->plugins) {
                g_slist_free(service->plugins);
@@ -208,6 +251,9 @@ gboolean zblib_service_remove_plugin(ZigBeeService *service, ZigBeePlugin *plugi
        /* Specific vendor plug-in would be removed */
        service->plugins = g_slist_remove(service->plugins, plugin);
 
+       /* Deinitialize plugin */
+       zblib_plugin_free(plugin);
+
        return TRUE;
 }
 
@@ -374,6 +420,7 @@ ZigBeeServiceInterface *zblib_service_ref_service_interface(ZigBeeService *servi
                        service_interface = tmp_service_interface;
                        break;
                }
+               g_free(object_name);
 
                list = g_slist_next(list);
        }