Coverage Report

Created: 2025-07-18 06:59

/src/zstd/lib/common/allocations.h
Line
Count
Source (jump to first uncovered line)
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
237k
{
28
237k
    if (customMem.customAlloc)
29
0
        return customMem.customAlloc(customMem.opaque, size);
30
237k
    return ZSTD_malloc(size);
31
237k
}
Unexecuted instantiation: sequence_producer.c:ZSTD_customMalloc
Unexecuted instantiation: pool.c:ZSTD_customMalloc
zstd_compress.c:ZSTD_customMalloc
Line
Count
Source
27
166k
{
28
166k
    if (customMem.customAlloc)
29
0
        return customMem.customAlloc(customMem.opaque, size);
30
166k
    return ZSTD_malloc(size);
31
166k
}
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
728
{
28
728
    if (customMem.customAlloc)
29
0
        return customMem.customAlloc(customMem.opaque, size);
30
728
    return ZSTD_malloc(size);
31
728
}
zstd_ddict.c:ZSTD_customMalloc
Line
Count
Source
27
43.3k
{
28
43.3k
    if (customMem.customAlloc)
29
0
        return customMem.customAlloc(customMem.opaque, size);
30
43.3k
    return ZSTD_malloc(size);
31
43.3k
}
zstd_decompress.c:ZSTD_customMalloc
Line
Count
Source
27
27.1k
{
28
27.1k
    if (customMem.customAlloc)
29
0
        return customMem.customAlloc(customMem.opaque, size);
30
27.1k
    return ZSTD_malloc(size);
31
27.1k
}
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
2.13k
{
35
2.13k
    if (customMem.customAlloc) {
36
        /* calloc implemented as malloc+memset;
37
         * not as efficient as calloc, but next best guess for custom malloc */
38
0
        void* const ptr = customMem.customAlloc(customMem.opaque, size);
39
0
        ZSTD_memset(ptr, 0, size);
40
0
        return ptr;
41
0
    }
42
2.13k
    return ZSTD_calloc(1, size);
43
2.13k
}
Unexecuted instantiation: sequence_producer.c:ZSTD_customCalloc
pool.c:ZSTD_customCalloc
Line
Count
Source
34
582
{
35
582
    if (customMem.customAlloc) {
36
        /* calloc implemented as malloc+memset;
37
         * not as efficient as calloc, but next best guess for custom malloc */
38
0
        void* const ptr = customMem.customAlloc(customMem.opaque, size);
39
0
        ZSTD_memset(ptr, 0, size);
40
0
        return ptr;
41
0
    }
42
582
    return ZSTD_calloc(1, size);
43
582
}
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
1.55k
{
35
1.55k
    if (customMem.customAlloc) {
36
        /* calloc implemented as malloc+memset;
37
         * not as efficient as calloc, but next best guess for custom malloc */
38
0
        void* const ptr = customMem.customAlloc(customMem.opaque, size);
39
0
        ZSTD_memset(ptr, 0, size);
40
0
        return ptr;
41
0
    }
42
1.55k
    return ZSTD_calloc(1, size);
43
1.55k
}
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
44
45
MEM_STATIC void ZSTD_customFree(void* ptr, ZSTD_customMem customMem)
46
460k
{
47
460k
    if (ptr!=NULL) {
48
239k
        if (customMem.customFree)
49
0
            customMem.customFree(customMem.opaque, ptr);
50
239k
        else
51
239k
            ZSTD_free(ptr);
52
239k
    }
53
460k
}
Unexecuted instantiation: sequence_producer.c:ZSTD_customFree
pool.c:ZSTD_customFree
Line
Count
Source
46
582
{
47
582
    if (ptr!=NULL) {
48
582
        if (customMem.customFree)
49
0
            customMem.customFree(customMem.opaque, ptr);
50
582
        else
51
582
            ZSTD_free(ptr);
52
582
    }
53
582
}
zstd_compress.c:ZSTD_customFree
Line
Count
Source
46
348k
{
47
348k
    if (ptr!=NULL) {
48
166k
        if (customMem.customFree)
49
0
            customMem.customFree(customMem.opaque, ptr);
50
166k
        else
51
166k
            ZSTD_free(ptr);
52
166k
    }
53
348k
}
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
46
3.79k
{
47
3.79k
    if (ptr!=NULL) {
48
2.28k
        if (customMem.customFree)
49
0
            customMem.customFree(customMem.opaque, ptr);
50
2.28k
        else
51
2.28k
            ZSTD_free(ptr);
52
2.28k
    }
53
3.79k
}
zstd_ddict.c:ZSTD_customFree
Line
Count
Source
46
54.1k
{
47
54.1k
    if (ptr!=NULL) {
48
43.3k
        if (customMem.customFree)
49
0
            customMem.customFree(customMem.opaque, ptr);
50
43.3k
        else
51
43.3k
            ZSTD_free(ptr);
52
43.3k
    }
53
54.1k
}
zstd_decompress.c:ZSTD_customFree
Line
Count
Source
46
54.3k
{
47
54.3k
    if (ptr!=NULL) {
48
27.1k
        if (customMem.customFree)
49
0
            customMem.customFree(customMem.opaque, ptr);
50
27.1k
        else
51
27.1k
            ZSTD_free(ptr);
52
27.1k
    }
53
54.3k
}
Unexecuted instantiation: fastcover.c:ZSTD_customFree
Unexecuted instantiation: zdict.c:ZSTD_customFree
54
55
#endif /* ZSTD_ALLOCATIONS_H */