Coverage Report

Created: 2026-05-16 07:29

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/fluent-bit/lib/cprofiles/cprof_instrumentation_scope.c
Line
Count
Source
1
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
3
/*  CProfiles
4
 *  =========
5
 *  Copyright (C) 2024 The CProfiles Authors
6
 *
7
 *  Licensed under the Apache License, Version 2.0 (the "License");
8
 *  you may not use this file except in compliance with the License.
9
 *  You may obtain a copy of the License at
10
 *
11
 *      http://www.apache.org/licenses/LICENSE-2.0
12
 *
13
 *  Unless required by applicable law or agreed to in writing, software
14
 *  distributed under the License is distributed on an "AS IS" BASIS,
15
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
 *  See the License for the specific language governing permissions and
17
 *  limitations under the License.
18
 */
19
20
21
#include <cprofiles/cprofiles.h>
22
23
struct cprof_instrumentation_scope *cprof_instrumentation_scope_create(
24
                                        char *name,
25
                                        char *version,
26
                                        struct cfl_kvlist *attributes,
27
0
                                        uint32_t dropped_attributes_count) {
28
0
    struct cprof_instrumentation_scope *instance;
29
30
0
    instance = calloc(1, sizeof(struct cprof_instrumentation_scope));
31
32
0
    if (instance == NULL) {
33
0
        return NULL;
34
0
    }
35
36
0
    if (name != NULL) {
37
0
        instance->name = cfl_sds_create(name);
38
39
0
        if (instance->name == NULL) {
40
0
            cprof_instrumentation_scope_destroy(instance);
41
42
0
            return NULL;
43
0
        }
44
0
    }
45
46
0
    if (version != NULL) {
47
0
        instance->version = cfl_sds_create(version);
48
49
0
        if (instance->version == NULL) {
50
0
            cprof_instrumentation_scope_destroy(instance);
51
52
0
            return NULL;
53
0
        }
54
0
    }
55
56
0
    if (attributes != NULL) {
57
0
        instance->attributes = attributes;
58
0
    }
59
0
    else {
60
0
        instance->attributes = cfl_kvlist_create();
61
62
0
        if (instance->attributes == NULL) {
63
0
            cprof_instrumentation_scope_destroy(instance);
64
65
0
            return NULL;
66
0
        }
67
0
    }
68
69
0
    instance->dropped_attributes_count = dropped_attributes_count;
70
71
0
    return instance;
72
0
}
73
74
void cprof_instrumentation_scope_destroy(
75
            struct cprof_instrumentation_scope *instance)
76
0
{
77
0
    if (instance != NULL) {
78
0
        if (instance->name != NULL) {
79
0
            cfl_sds_destroy(instance->name);
80
0
        }
81
82
0
        if (instance->version != NULL) {
83
0
            cfl_sds_destroy(instance->version);
84
0
        }
85
86
0
        if (instance->attributes != NULL) {
87
0
            cfl_kvlist_destroy(instance->attributes);
88
0
        }
89
90
0
        free(instance);
91
0
    }
92
0
}