Coverage Report

Created: 2026-04-12 07:11

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/zstd/lib/common/allocations.h
Line
Count
Source
1
/*
2
 * Copyright (c) Meta Platforms, Inc. and affiliates.
3
 * All rights reserved.
4
 *
5
 * This source code is licensed under both the BSD-style license (found in the
6
 * LICENSE file in the root directory of this source tree) and the GPLv2 (found
7
 * in the COPYING file in the root directory of this source tree).
8
 * You may select, at your option, one of the above-listed licenses.
9
 */
10
11
/* This file provides custom allocation primitives
12
 */
13
14
#define ZSTD_DEPS_NEED_MALLOC
15
#include "zstd_deps.h"   /* ZSTD_malloc, ZSTD_calloc, ZSTD_free, ZSTD_memset */
16
17
#include "compiler.h" /* MEM_STATIC */
18
#define ZSTD_STATIC_LINKING_ONLY
19
#include "../zstd.h" /* ZSTD_customMem */
20
21
#ifndef ZSTD_ALLOCATIONS_H
22
#define ZSTD_ALLOCATIONS_H
23
24
/* custom memory allocation functions */
25
26
MEM_STATIC void* ZSTD_customMalloc(size_t size, ZSTD_customMem customMem)
27
1.77M
{
28
1.77M
    if (customMem.customAlloc)
29
0
        return customMem.customAlloc(customMem.opaque, size);
30
1.77M
    return ZSTD_malloc(size);
31
1.77M
}
Unexecuted instantiation: sequence_producer.c:ZSTD_customMalloc
Unexecuted instantiation: pool.c:ZSTD_customMalloc
zstd_compress.c:ZSTD_customMalloc
Line
Count
Source
27
1.06M
{
28
1.06M
    if (customMem.customAlloc)
29
0
        return customMem.customAlloc(customMem.opaque, size);
30
1.06M
    return ZSTD_malloc(size);
31
1.06M
}
Unexecuted instantiation: zstd_compress_literals.c:ZSTD_customMalloc
Unexecuted instantiation: zstd_compress_sequences.c:ZSTD_customMalloc
Unexecuted instantiation: zstd_compress_superblock.c:ZSTD_customMalloc
Unexecuted instantiation: zstd_double_fast.c:ZSTD_customMalloc
Unexecuted instantiation: zstd_fast.c:ZSTD_customMalloc
Unexecuted instantiation: zstd_lazy.c:ZSTD_customMalloc
Unexecuted instantiation: zstd_ldm.c:ZSTD_customMalloc
Unexecuted instantiation: zstd_opt.c:ZSTD_customMalloc
zstdmt_compress.c:ZSTD_customMalloc
Line
Count
Source
27
106k
{
28
106k
    if (customMem.customAlloc)
29
0
        return customMem.customAlloc(customMem.opaque, size);
30
106k
    return ZSTD_malloc(size);
31
106k
}
zstd_ddict.c:ZSTD_customMalloc
Line
Count
Source
27
219k
{
28
219k
    if (customMem.customAlloc)
29
0
        return customMem.customAlloc(customMem.opaque, size);
30
219k
    return ZSTD_malloc(size);
31
219k
}
zstd_decompress.c:ZSTD_customMalloc
Line
Count
Source
27
385k
{
28
385k
    if (customMem.customAlloc)
29
0
        return customMem.customAlloc(customMem.opaque, size);
30
385k
    return ZSTD_malloc(size);
31
385k
}
Unexecuted instantiation: fastcover.c:ZSTD_customMalloc
Unexecuted instantiation: zdict.c:ZSTD_customMalloc
32
33
MEM_STATIC void* ZSTD_customCalloc(size_t size, ZSTD_customMem customMem)
34
334k
{
35
334k
    if (customMem.customAlloc) {
36
        /* calloc implemented as malloc+memset */
37
0
        void* const ptr = customMem.customAlloc(customMem.opaque, size);
38
39
0
        if (ptr == NULL) {
40
0
            return NULL;
41
0
        }
42
43
0
        ZSTD_memset(ptr, 0, size);
44
0
        return ptr;
45
0
    }
46
334k
    return ZSTD_calloc(1, size);
47
334k
}
Unexecuted instantiation: sequence_producer.c:ZSTD_customCalloc
pool.c:ZSTD_customCalloc
Line
Count
Source
34
91.0k
{
35
91.0k
    if (customMem.customAlloc) {
36
        /* calloc implemented as malloc+memset */
37
0
        void* const ptr = customMem.customAlloc(customMem.opaque, size);
38
39
0
        if (ptr == NULL) {
40
0
            return NULL;
41
0
        }
42
43
0
        ZSTD_memset(ptr, 0, size);
44
0
        return ptr;
45
0
    }
46
91.0k
    return ZSTD_calloc(1, size);
47
91.0k
}
Unexecuted instantiation: zstd_compress.c:ZSTD_customCalloc
Unexecuted instantiation: zstd_compress_literals.c:ZSTD_customCalloc
Unexecuted instantiation: zstd_compress_sequences.c:ZSTD_customCalloc
Unexecuted instantiation: zstd_compress_superblock.c:ZSTD_customCalloc
Unexecuted instantiation: zstd_double_fast.c:ZSTD_customCalloc
Unexecuted instantiation: zstd_fast.c:ZSTD_customCalloc
Unexecuted instantiation: zstd_lazy.c:ZSTD_customCalloc
Unexecuted instantiation: zstd_ldm.c:ZSTD_customCalloc
Unexecuted instantiation: zstd_opt.c:ZSTD_customCalloc
zstdmt_compress.c:ZSTD_customCalloc
Line
Count
Source
34
243k
{
35
243k
    if (customMem.customAlloc) {
36
        /* calloc implemented as malloc+memset */
37
0
        void* const ptr = customMem.customAlloc(customMem.opaque, size);
38
39
0
        if (ptr == NULL) {
40
0
            return NULL;
41
0
        }
42
43
0
        ZSTD_memset(ptr, 0, size);
44
0
        return ptr;
45
0
    }
46
243k
    return ZSTD_calloc(1, size);
47
243k
}
Unexecuted instantiation: zstd_ddict.c:ZSTD_customCalloc
Unexecuted instantiation: zstd_decompress.c:ZSTD_customCalloc
Unexecuted instantiation: fastcover.c:ZSTD_customCalloc
Unexecuted instantiation: zdict.c:ZSTD_customCalloc
48
49
MEM_STATIC void ZSTD_customFree(void* ptr, ZSTD_customMem customMem)
50
4.00M
{
51
4.00M
    if (ptr!=NULL) {
52
2.10M
        if (customMem.customFree)
53
0
            customMem.customFree(customMem.opaque, ptr);
54
2.10M
        else
55
2.10M
            ZSTD_free(ptr);
56
2.10M
    }
57
4.00M
}
Unexecuted instantiation: sequence_producer.c:ZSTD_customFree
pool.c:ZSTD_customFree
Line
Count
Source
50
91.0k
{
51
91.0k
    if (ptr!=NULL) {
52
91.0k
        if (customMem.customFree)
53
0
            customMem.customFree(customMem.opaque, ptr);
54
91.0k
        else
55
91.0k
            ZSTD_free(ptr);
56
91.0k
    }
57
91.0k
}
zstd_compress.c:ZSTD_customFree
Line
Count
Source
50
2.33M
{
51
2.33M
    if (ptr!=NULL) {
52
1.06M
        if (customMem.customFree)
53
0
            customMem.customFree(customMem.opaque, ptr);
54
1.06M
        else
55
1.06M
            ZSTD_free(ptr);
56
1.06M
    }
57
2.33M
}
Unexecuted instantiation: zstd_compress_literals.c:ZSTD_customFree
Unexecuted instantiation: zstd_compress_sequences.c:ZSTD_customFree
Unexecuted instantiation: zstd_compress_superblock.c:ZSTD_customFree
Unexecuted instantiation: zstd_double_fast.c:ZSTD_customFree
Unexecuted instantiation: zstd_fast.c:ZSTD_customFree
Unexecuted instantiation: zstd_lazy.c:ZSTD_customFree
Unexecuted instantiation: zstd_ldm.c:ZSTD_customFree
Unexecuted instantiation: zstd_opt.c:ZSTD_customFree
zstdmt_compress.c:ZSTD_customFree
Line
Count
Source
50
582k
{
51
582k
    if (ptr!=NULL) {
52
350k
        if (customMem.customFree)
53
0
            customMem.customFree(customMem.opaque, ptr);
54
350k
        else
55
350k
            ZSTD_free(ptr);
56
350k
    }
57
582k
}
zstd_ddict.c:ZSTD_customFree
Line
Count
Source
50
275k
{
51
275k
    if (ptr!=NULL) {
52
219k
        if (customMem.customFree)
53
0
            customMem.customFree(customMem.opaque, ptr);
54
219k
        else
55
219k
            ZSTD_free(ptr);
56
219k
    }
57
275k
}
zstd_decompress.c:ZSTD_customFree
Line
Count
Source
50
720k
{
51
720k
    if (ptr!=NULL) {
52
385k
        if (customMem.customFree)
53
0
            customMem.customFree(customMem.opaque, ptr);
54
385k
        else
55
385k
            ZSTD_free(ptr);
56
385k
    }
57
720k
}
Unexecuted instantiation: fastcover.c:ZSTD_customFree
Unexecuted instantiation: zdict.c:ZSTD_customFree
58
59
#endif /* ZSTD_ALLOCATIONS_H */