1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00

memarray: use memarray_free to init elements

This commit is contained in:
Koen Zandberg 2020-12-18 14:19:22 +01:00
parent bb1a3470d7
commit 5495da5840
No known key found for this signature in database
GPG Key ID: 0895A893E6D2985B

View File

@ -21,13 +21,13 @@ void memarray_init(memarray_t *mem, void *data, size_t size, size_t num)
DEBUG("memarray: Initialize memarray of %u times %u Bytes at %p\n",
(unsigned)num, (unsigned)size, data);
mem->free_data = data;
mem->free_data = NULL;
mem->size = size;
mem->num = num;
for (size_t i = 0; i < (mem->num - 1); i++) {
void *next = ((char *)mem->free_data) + ((i + 1) * mem->size);
memcpy(((char *)mem->free_data) + (i * mem->size), &next, sizeof(void *));
for (uint8_t *element = data;
element < (uint8_t*)data + (num * size);
element += size) {
memarray_free(mem, element);
}
memset(((char *)mem->free_data) + ((mem->num - 1) * (mem->size)), 0, sizeof(void *));
}