static void s_clean_up_custom_metric_data()

in source/device_defender.c [621:658]


static void s_clean_up_custom_metric_data(
    struct aws_allocator *allocator,
    struct defender_custom_metric_data *custom_metrics_data,
    const size_t custom_metrics_len) {
    AWS_PRECONDITION(allocator != NULL);

    if (custom_metrics_data) {
        for (size_t metric_index = 0; metric_index < custom_metrics_len; ++metric_index) {
            size_t list_size = 0; /* set only if we have a list type */
            /* if metric is a NULL ptr, then data was never populated and it is not safe to
               dereference pointer to metric as it is NULL */
            if (custom_metrics_data[metric_index].metric) {
                switch (custom_metrics_data[metric_index].metric->type) {
                    case DD_METRIC_NUMBER: /* nothing to do here */
                        break;
                    case DD_METRIC_STRING_LIST:
                    /* fall through */
                    case DD_METRIC_IP_LIST:
                        list_size = aws_array_list_length(&custom_metrics_data[metric_index].data.list);
                        for (size_t item_index = 0; item_index < list_size; ++item_index) {
                            struct aws_string *string_or_ip_entry;
                            aws_array_list_get_at(
                                &custom_metrics_data[metric_index].data.list, (void *)&string_or_ip_entry, item_index);
                            aws_string_destroy(string_or_ip_entry);
                        }
                    /* fall through */
                    case DD_METRIC_NUMBER_LIST:
                        aws_array_list_clean_up(&custom_metrics_data[metric_index].data.list);
                        break;
                    case DD_METRIC_UNKNOWN:
                    default:
                        break;
                }
            }
        }
        aws_mem_release(allocator, custom_metrics_data);
    }
}