Coverage Report

Created: 2025-10-08 19:34

/work/toxcore/tox_memory.c
Line
Count
Source (jump to first uncovered line)
1
/* SPDX-License-Identifier: GPL-3.0-or-later
2
 * Copyright © 2016-2025 The TokTok team.
3
 * Copyright © 2013 Tox project.
4
 */
5
#include "tox_memory.h"
6
7
#include <string.h>
8
9
#include "ccompat.h"
10
#include "tox_memory_impl.h"  // IWYU pragma: keep
11
12
Tox_Memory *tox_memory_new(const Tox_Memory_Funcs *funcs, void *user_data)
13
0
{
14
0
    const Tox_Memory bootstrap = {funcs, user_data};
15
16
0
    Tox_Memory *mem = (Tox_Memory *)tox_memory_alloc(&bootstrap, sizeof(Tox_Memory));
17
18
0
    if (mem == nullptr) {
19
0
        return nullptr;
20
0
    }
21
22
0
    *mem = bootstrap;
23
24
0
    return mem;
25
0
}
26
27
void tox_memory_free(Tox_Memory *mem)
28
0
{
29
0
    if (mem == nullptr) {
30
0
        return;
31
0
    }
32
33
0
    tox_memory_dealloc(mem, mem);
34
0
}
35
36
void *tox_memory_malloc(const Tox_Memory *mem, uint32_t size)
37
6.43M
{
38
6.43M
    void *const ptr = mem->funcs->malloc_callback(mem->user_data, size);
39
6.43M
    return ptr;
40
6.43M
}
41
42
void *tox_memory_alloc(const Tox_Memory *mem, uint32_t size)
43
0
{
44
0
    void *const ptr = tox_memory_malloc(mem, size);
45
0
    if (ptr != nullptr) {
46
0
        memset(ptr, 0, size);
47
0
    }
48
0
    return ptr;
49
0
}
50
51
void *tox_memory_realloc(const Tox_Memory *mem, void *ptr, uint32_t size)
52
136k
{
53
136k
    void *const new_ptr = mem->funcs->realloc_callback(mem->user_data, ptr, size);
54
136k
    return new_ptr;
55
136k
}
56
57
void tox_memory_dealloc(const Tox_Memory *mem, void *ptr)
58
9.05M
{
59
9.05M
    mem->funcs->dealloc_callback(mem->user_data, ptr);
60
9.05M
}