Coverage Report

Created: 2026-11-22 17:17

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/hdf5/src/H5HLint.c
Line
Count
Source
1
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
2
 * Copyright by The HDF Group.                                               *
3
 * All rights reserved.                                                      *
4
 *                                                                           *
5
 * This file is part of HDF5.  The full HDF5 copyright notice, including     *
6
 * terms governing use, modification, and redistribution, is contained in    *
7
 * the LICENSE file, which can be found at the root of the source code       *
8
 * distribution tree, or in https://www.hdfgroup.org/licenses.               *
9
 * If you do not have access to either file, you may request a copy from     *
10
 * help@hdfgroup.org.                                                        *
11
 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
12
13
/*-------------------------------------------------------------------------
14
 *
15
 * Created:     H5HLint.c
16
 *
17
 * Purpose:     Local heap internal routines.
18
 *
19
 *-------------------------------------------------------------------------
20
 */
21
22
/****************/
23
/* Module Setup */
24
/****************/
25
26
#include "H5HLmodule.h" /* This source code file is part of the H5HL module */
27
28
/***********/
29
/* Headers */
30
/***********/
31
#include "H5private.h"   /* Generic Functions            */
32
#include "H5Eprivate.h"  /* Error handling               */
33
#include "H5FLprivate.h" /* Free lists                   */
34
#include "H5HLpkg.h"     /* Local Heaps                  */
35
36
/****************/
37
/* Local Macros */
38
/****************/
39
40
/******************/
41
/* Local Typedefs */
42
/******************/
43
44
/********************/
45
/* Package Typedefs */
46
/********************/
47
48
/********************/
49
/* Local Prototypes */
50
/********************/
51
52
/*********************/
53
/* Package Variables */
54
/*********************/
55
56
/*****************************/
57
/* Library Private Variables */
58
/*****************************/
59
60
/*******************/
61
/* Local Variables */
62
/*******************/
63
64
/* Declare a free list to manage the H5HL_t struct */
65
H5FL_DEFINE_STATIC(H5HL_t);
66
67
/*-------------------------------------------------------------------------
68
 * Function:    H5HL__new
69
 *
70
 * Purpose:     Create a new local heap object
71
 *
72
 * Return:      Success:    non-NULL pointer to new local heap
73
 *              Failure:    NULL
74
 *
75
 *-------------------------------------------------------------------------
76
 */
77
H5HL_t *
78
H5HL__new(size_t sizeof_size, size_t sizeof_addr, size_t prfx_size)
79
713
{
80
713
    H5HL_t *heap      = NULL; /* New local heap */
81
713
    H5HL_t *ret_value = NULL;
82
83
713
    FUNC_ENTER_PACKAGE
84
85
    /* check arguments */
86
713
    assert(sizeof_size > 0);
87
713
    assert(sizeof_addr > 0);
88
713
    assert(prfx_size > 0);
89
90
    /* Allocate new local heap structure */
91
713
    if (NULL == (heap = H5FL_CALLOC(H5HL_t)))
92
0
        HGOTO_ERROR(H5E_HEAP, H5E_CANTALLOC, NULL, "memory allocation failed");
93
94
    /* Initialize non-zero fields */
95
713
    heap->sizeof_size = sizeof_size;
96
713
    heap->sizeof_addr = sizeof_addr;
97
713
    heap->prfx_size   = prfx_size;
98
99
    /* Set the return value */
100
713
    ret_value = heap;
101
102
713
done:
103
713
    if (!ret_value && heap != NULL)
104
0
        if (NULL == (heap = H5FL_FREE(H5HL_t, heap)))
105
0
            HDONE_ERROR(H5E_HEAP, H5E_CANTFREE, NULL, "can't free heap memory");
106
107
713
    FUNC_LEAVE_NOAPI(ret_value)
108
713
} /* end H5HL__new() */
109
110
/*-------------------------------------------------------------------------
111
 * Function:  H5HL__inc_rc
112
 *
113
 * Purpose:     Increment ref. count on heap
114
 *
115
 * Return:      SUCCEED (Can't fail)
116
 *
117
 *-------------------------------------------------------------------------
118
 */
119
herr_t
120
H5HL__inc_rc(H5HL_t *heap)
121
980
{
122
980
    FUNC_ENTER_PACKAGE_NOERR
123
124
    /* check arguments */
125
980
    assert(heap);
126
127
    /* Increment heap's ref. count */
128
980
    heap->rc++;
129
130
980
    FUNC_LEAVE_NOAPI(SUCCEED)
131
980
} /* end H5HL__inc_rc() */
132
133
/*-------------------------------------------------------------------------
134
 * Function:  H5HL__dec_rc
135
 *
136
 * Purpose:     Decrement ref. count on heap
137
 *
138
 * Return:      SUCCEED/FAIL
139
 *
140
 *-------------------------------------------------------------------------
141
 */
142
herr_t
143
H5HL__dec_rc(H5HL_t *heap)
144
980
{
145
980
    herr_t ret_value = SUCCEED;
146
147
980
    FUNC_ENTER_PACKAGE
148
149
    /* check arguments */
150
980
    assert(heap);
151
152
    /* Decrement heap's ref. count */
153
980
    heap->rc--;
154
155
    /* Check if we should destroy the heap */
156
980
    if (heap->rc == 0 && FAIL == H5HL__dest(heap))
157
0
        HGOTO_ERROR(H5E_HEAP, H5E_CANTFREE, FAIL, "unable to destroy local heap");
158
159
980
done:
160
980
    FUNC_LEAVE_NOAPI(ret_value)
161
980
} /* end H5HL__dec_rc() */
162
163
/*-------------------------------------------------------------------------
164
 * Function:    H5HL__dest
165
 *
166
 * Purpose:     Destroys a heap in memory.
167
 *
168
 * Return:      SUCCEED/FAIL
169
 *
170
 *-------------------------------------------------------------------------
171
 */
172
herr_t
173
H5HL__dest(H5HL_t *heap)
174
713
{
175
713
    herr_t ret_value = SUCCEED;
176
177
713
    FUNC_ENTER_PACKAGE
178
179
    /* check arguments */
180
713
    assert(heap);
181
182
    /* Verify that node is unused */
183
713
    assert(heap->prots == 0);
184
713
    assert(heap->rc == 0);
185
713
    assert(heap->prfx == NULL);
186
713
    assert(heap->dblk == NULL);
187
188
    /* Use DONE errors here to try to free as much as possible */
189
713
    if (heap->dblk_image)
190
711
        if (NULL != (heap->dblk_image = H5FL_BLK_FREE(lheap_chunk, heap->dblk_image)))
191
0
            HDONE_ERROR(H5E_HEAP, H5E_CANTFREE, FAIL, "unable to free local heap data block image");
192
1.41k
    while (heap->freelist) {
193
702
        H5HL_free_t *fl;
194
195
702
        fl             = heap->freelist;
196
702
        heap->freelist = fl->next;
197
702
        if (NULL != (fl = H5FL_FREE(H5HL_free_t, fl)))
198
0
            HDONE_ERROR(H5E_HEAP, H5E_CANTFREE, FAIL, "unable to free local heap free list");
199
702
    }
200
201
713
    if (NULL != (heap = H5FL_FREE(H5HL_t, heap)))
202
0
        HDONE_ERROR(H5E_HEAP, H5E_CANTFREE, FAIL, "unable to free local heap");
203
204
713
    FUNC_LEAVE_NOAPI(ret_value)
205
713
} /* end H5HL__dest() */