Line | Branch | Exec | Source |
---|---|---|---|
1 | /* | ||
2 | ** EPITECH PROJECT, 2024 | ||
3 | ** my_malloc | ||
4 | ** File description: | ||
5 | ** Free allocated memory (type 0) or allocates memory (type 1) | ||
6 | ** of a certain size (size) | ||
7 | */ | ||
8 | /** | ||
9 | * @file my_malloc.c | ||
10 | * @brief The file containing the my_malloc function | ||
11 | * @author Nicolas TORO | ||
12 | */ | ||
13 | |||
14 | #include "mymemory.h" | ||
15 | |||
16 | 20145 | void *my_malloc(size_t size, int type) | |
17 | { | ||
18 | static node_t *list = NULL; | ||
19 | void *ptr; | ||
20 | |||
21 |
4/4✓ Branch 0 taken 19224 times.
✓ Branch 1 taken 921 times.
✓ Branch 2 taken 19223 times.
✓ Branch 3 taken 1 times.
|
20145 | if (type == 1 && size > 0) { |
22 | 19223 | ptr = malloc(size); | |
23 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 19222 times.
|
19223 | if (ptr == NULL) |
24 | 1 | return NULL; | |
25 | 19222 | my_push_front(&list, ptr, VOID); | |
26 | 19222 | return ptr; | |
27 | } | ||
28 |
2/2✓ Branch 0 taken 921 times.
✓ Branch 1 taken 1 times.
|
922 | if (type == 0) |
29 | 921 | my_delete_list(&list); | |
30 | 922 | return NULL; | |
31 | } | ||
32 |