• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

mendersoftware / mender-mcu / 1642556678

27 Jan 2025 01:30PM UTC coverage: 25.749%. First build
1642556678

push

gitlab-ci

vpodzime
feat: Support platform-specific or custom allocators

And use Zephyr-specific allocation functions on Zephyr by
default, using either a separate heap (default) or the system
heap.

This means we have to use our memory management functions instead
of the standard ones everywhere, even if they can actually just
call the standard ones.

Ticket: MEN-7808
Changelog: none
Signed-off-by: Vratislav Podzimek <vratislav.podzimek@northern.tech>

64 of 184 new or added lines in 12 files covered. (34.78%)

731 of 2839 relevant lines covered (25.75%)

8.54 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

65.22
/core/src/mender-alloc.c
1
/**
2
 * @file      mender-alloc.c
3
 * @brief     Platform-independent parts of the Mender memory management implementation
4
 *
5
 * Copyright Northern.tech AS
6
 *
7
 * Licensed under the Apache License, Version 2.0 (the "License");
8
 * you may not use this file except in compliance with the License.
9
 * You may obtain a copy of the License at
10
 *
11
 *     http://www.apache.org/licenses/LICENSE-2.0
12
 *
13
 * Unless required by applicable law or agreed to in writing, software
14
 * distributed under the License is distributed on an "AS IS" BASIS,
15
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
 * See the License for the specific language governing permissions and
17
 * limitations under the License.
18
 */
19

20
#include <stdlib.h> /* malloc(),... */
21
#include <string.h> /* memset() */
22

23
#include "mender-alloc.h"
24

25
static MenderAllocator   malloc_fn  = NULL;
26
static MenderReallocator realloc_fn = NULL;
27
static MenderDeallocator free_fn    = NULL;
28

29
void
NEW
30
mender_set_allocation_funcs(MenderAllocator malloc_func, MenderReallocator realloc_func, MenderDeallocator free_func) {
×
NEW
31
    malloc_fn  = malloc_func;
×
NEW
32
    realloc_fn = realloc_func;
×
NEW
33
    free_fn    = free_func;
×
NEW
34
}
×
35

36
void *
37
mender_malloc(size_t size) {
319✔
38
    if (NULL == malloc_fn) {
319✔
39
        return malloc(size);
319✔
40
    }
NEW
41
    return malloc_fn(size);
×
42
}
43

44
void *
45
mender_calloc(size_t n, size_t size) {
82✔
46
    void *ret = mender_malloc(n * size);
82✔
47
    if (NULL != ret) {
82✔
48
        memset(ret, 0, n * size);
82✔
49
    }
50
    return ret;
82✔
51
}
52

53
void *
54
mender_realloc(void *ptr, size_t size) {
23✔
55
    if (NULL == realloc_fn) {
23✔
56
        return realloc(ptr, size);
23✔
57
    }
NEW
58
    return realloc_fn(ptr, size);
×
59
}
60

61
void
62
mender_free(void *ptr) {
421✔
63
    if (NULL == free_fn) {
421✔
64
        free(ptr);
421✔
65
        return;
421✔
66
    }
NEW
67
    free_fn(ptr);
×
68
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc