Fix coverity issues
[platform/core/connectivity/zigbee-manager.git] / zigbee-daemon / zigbee-interface / src / zigbee_service_dbus_interface_zcl_global_control.c
index 9c5a0e8..1478f0e 100644 (file)
@@ -1455,16 +1455,16 @@ void zigbee_service_dbus_interface_zcl_global_control_notification(ZigBeeService
                        TRUE, NULL, NULL);
                if (NULL == v_types || NULL == v_attrs) {
                        Z_LOGE("Failed to create variant!");
-                       if (v_types)
-                               g_variant_unref(v_types);
-                       if (v_attrs)
-                               g_variant_unref(v_attrs);
                } else {
                        Z_LOGD("Discover attribute resp");
                        zigbee_zcl_global_control_emit_discover_attribute_rsp(global_control_object,
                                attr_t->node_id, attr_t->src_ep, v_types, v_attrs,
                                attr_t->cluster_id, attr_t->record_length, attr_t->discovery_completed);
                }
+               if (v_types)
+                       g_variant_unref(v_types);
+               if (v_attrs)
+                       g_variant_unref(v_attrs);
        break;
        }
        case ZBLIB_ZCL_GLOBAL_NOTI_WRITE_ATTR_STRUCTURED_RSP: {
@@ -1518,6 +1518,12 @@ void zigbee_service_dbus_interface_zcl_global_control_notification(ZigBeeService
                        v_status, v_attrs, v_indicator, v_index,
                        attr_t->cluster_id, attr_t->record_length,
                        attr_t->node_id, attr_t->src_ep);
+               if (v_status)
+                       g_variant_unref(v_status);
+               if (v_attrs)
+                       g_variant_unref(v_attrs);
+               if (v_indicator)
+                       g_variant_unref(v_indicator);
        break;
        }
        case ZBLIB_ZCL_GLOBAL_NOTI_DISCOVER_CMDS_RECEIVED_RSP: {
@@ -1536,6 +1542,8 @@ void zigbee_service_dbus_interface_zcl_global_control_notification(ZigBeeService
                                v_commands, attr_t->cluster_id, attr_t->list_count,
                                attr_t->node_id, attr_t->src_ep, attr_t->discovery_completed);
                }
+               if (v_commands)
+                       g_variant_unref(v_commands);
        break;
        }
        case ZBLIB_ZCL_GLOBAL_NOTI_DISCOVER_CMDS_GENERATED_RSP: {
@@ -1554,6 +1562,8 @@ void zigbee_service_dbus_interface_zcl_global_control_notification(ZigBeeService
                                v_commands, attr_t->cluster_id, attr_t->list_count,
                                attr_t->node_id, attr_t->src_ep, attr_t->discovery_completed);
                }
+               if (v_commands)
+                       g_variant_unref(v_commands);
        break;
        }
        case ZBLIB_ZCL_GLOBAL_NOTI_DISCOVER_ATTR_EXT_RSP: {
@@ -1572,12 +1582,6 @@ void zigbee_service_dbus_interface_zcl_global_control_notification(ZigBeeService
                        attr_t->access_list, attr_t->list_count, TRUE, NULL, NULL);
                if (NULL == v_attrs_type || NULL == v_attrs || NULL == v_access) {
                        Z_LOGE("Failed to create variant!");
-                       if (v_attrs_type)
-                               g_variant_unref(v_attrs_type);
-                       if (v_attrs)
-                               g_variant_unref(v_attrs);
-                       if (v_access)
-                               g_variant_unref(v_access);
                } else {
                        Z_LOGD("Discover attributes extended resp");
                        zigbee_zcl_global_control_emit_discover_attributes_extended_rsp(
@@ -1586,6 +1590,12 @@ void zigbee_service_dbus_interface_zcl_global_control_notification(ZigBeeService
                                attr_t->cluster_id, attr_t->list_count,
                                attr_t->node_id, attr_t->src_ep, attr_t->discovery_completed);
                }
+               if (v_attrs_type)
+                       g_variant_unref(v_attrs_type);
+               if (v_attrs)
+                       g_variant_unref(v_attrs);
+               if (v_access)
+                       g_variant_unref(v_access);
        break;
        }
        case ZBLIB_ZCL_GLOBAL_NOTI_DEFAULT_RSP: {
@@ -1612,12 +1622,14 @@ void zigbee_service_dbus_interface_zcl_global_control_notification(ZigBeeService
                v_attrs = g_variant_new_from_data(G_VARIANT_TYPE("aq"),
                        attr_t->attribute_list, (sizeof(gushort) * attr_t->list_count),
                        TRUE, NULL, NULL);
+               if (NULL == v_attrs) {
+                       Z_LOGE("Failed to create variant!");
+                       break;
+               }
                v_data_type = g_variant_new_from_data(G_VARIANT_TYPE("a(y)"),
                        attr_t->data_type_list, attr_t->list_count, TRUE, NULL, NULL);
-               if (NULL == v_data_type || NULL == v_attrs) {
+               if (NULL == v_data_type) {
                        Z_LOGE("Failed to create variant!");
-                       if (v_data_type)
-                               g_variant_unref(v_data_type);
                        if (v_attrs)
                                g_variant_unref(v_attrs);
                        break;
@@ -1626,8 +1638,10 @@ void zigbee_service_dbus_interface_zcl_global_control_notification(ZigBeeService
                values_builder = g_variant_builder_new(G_VARIANT_TYPE("a(y)"));
                if (NULL == values_builder) {
                        Z_LOGE("Failed to create variant builder!");
-                       g_variant_unref(v_data_type);
-                       g_variant_unref(v_attrs);
+                       if (v_attrs)
+                               g_variant_unref(v_attrs);
+                       if (v_data_type)
+                               g_variant_unref(v_data_type);
                        break;
                }
                for (i = 0; i < attr_t->list_count; i++) {
@@ -1643,6 +1657,12 @@ void zigbee_service_dbus_interface_zcl_global_control_notification(ZigBeeService
                        attr_t->node_id, attr_t->src_ep, attr_t->cluster_id,
                        v_attrs, v_data_type, v_values,
                        attr_t->list_count);
+               if (v_attrs)
+                       g_variant_unref(v_attrs);
+               if (v_data_type)
+                       g_variant_unref(v_data_type);
+               if (v_values)
+                       g_variant_unref(v_values);
        break;
        }
        case ZBLIB_ZCL_GLOBAL_NOTI_READ_CONFIG_REPORT_RSP: {
@@ -1693,6 +1713,9 @@ void zigbee_service_dbus_interface_zcl_global_control_notification(ZigBeeService
                zigbee_zcl_global_control_emit_read_configure_reporting_rsp(
                        global_control_object, resp_t->node_id, resp_t->src_ep,
                        resp_t->cluster_id, resp_t->record_count, v_entries);
+
+               if (v_entries)
+                       g_variant_unref(v_entries);
        break;
        }
        default: