Coverage Report

Created: 2026-04-01 07:49

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
13.1k
{
28
13.1k
    if (customMem.customAlloc)
29
0
        return customMem.customAlloc(customMem.opaque, size);
30
13.1k
    return ZSTD_malloc(size);
31
13.1k
}
zstd_compress.c:ZSTD_customMalloc
Line
Count
Source
27
3.52k
{
28
3.52k
    if (customMem.customAlloc)
29
0
        return customMem.customAlloc(customMem.opaque, size);
30
3.52k
    return ZSTD_malloc(size);
31
3.52k
}
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
Unexecuted instantiation: zstdmt_compress.c:ZSTD_customMalloc
zstd_decompress.c:ZSTD_customMalloc
Line
Count
Source
27
9.60k
{
28
9.60k
    if (customMem.customAlloc)
29
0
        return customMem.customAlloc(customMem.opaque, size);
30
9.60k
    return ZSTD_malloc(size);
31
9.60k
}
Unexecuted instantiation: pool.c:ZSTD_customMalloc
Unexecuted instantiation: zstd_ddict.c:ZSTD_customMalloc
32
33
MEM_STATIC void* ZSTD_customCalloc(size_t size, ZSTD_customMem customMem)
34
0
{
35
0
    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
0
    return ZSTD_calloc(1, size);
47
0
}
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
Unexecuted instantiation: zstdmt_compress.c:ZSTD_customCalloc
Unexecuted instantiation: zstd_decompress.c:ZSTD_customCalloc
Unexecuted instantiation: pool.c:ZSTD_customCalloc
Unexecuted instantiation: zstd_ddict.c:ZSTD_customCalloc
48
49
MEM_STATIC void ZSTD_customFree(void* ptr, ZSTD_customMem customMem)
50
26.4k
{
51
26.4k
    if (ptr!=NULL) {
52
13.1k
        if (customMem.customFree)
53
0
            customMem.customFree(customMem.opaque, ptr);
54
13.1k
        else
55
13.1k
            ZSTD_free(ptr);
56
13.1k
    }
57
26.4k
}
zstd_compress.c:ZSTD_customFree
Line
Count
Source
50
11.7k
{
51
11.7k
    if (ptr!=NULL) {
52
3.52k
        if (customMem.customFree)
53
0
            customMem.customFree(customMem.opaque, ptr);
54
3.52k
        else
55
3.52k
            ZSTD_free(ptr);
56
3.52k
    }
57
11.7k
}
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
Unexecuted instantiation: zstdmt_compress.c:ZSTD_customFree
zstd_decompress.c:ZSTD_customFree
Line
Count
Source
50
14.6k
{
51
14.6k
    if (ptr!=NULL) {
52
9.60k
        if (customMem.customFree)
53
0
            customMem.customFree(customMem.opaque, ptr);
54
9.60k
        else
55
9.60k
            ZSTD_free(ptr);
56
9.60k
    }
57
14.6k
}
Unexecuted instantiation: pool.c:ZSTD_customFree
Unexecuted instantiation: zstd_ddict.c:ZSTD_customFree
58
59
#endif /* ZSTD_ALLOCATIONS_H */