Skip to content

Commit e59f6a8

Browse files
aescolarfabiobaltieri
authored andcommitted
portability cmsis_rtosv2: Check return of k_mem_slab_init()
Instead of trusting blindly that k_mem_slab_init() will succeed, let's check it, and handle failures appropriately. Otherwise, a buffer of garbage will be passed around, leading to misterious failures later on. Signed-off-by: Alberto Escolar Piedras <[email protected]>
1 parent 5850636 commit e59f6a8

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

subsys/portability/cmsis_rtos_v2/mempool.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,15 @@ osMemoryPoolId_t osMemoryPoolNew(uint32_t block_count, uint32_t block_size,
6868
mslab->is_dynamic_allocation = FALSE;
6969
}
7070

71-
k_mem_slab_init(&mslab->z_mslab, mslab->pool, block_size, block_count);
71+
int rc = k_mem_slab_init(&mslab->z_mslab, mslab->pool, block_size, block_count);
72+
73+
if (rc != 0) {
74+
k_mem_slab_free(&cv2_mem_slab, (void *) &mslab);
75+
if (attr->mp_mem == NULL) {
76+
k_free(mslab->pool);
77+
}
78+
return NULL;
79+
}
7280

7381
if (attr->name == NULL) {
7482
strncpy(mslab->name, init_mslab_attrs.name,

0 commit comments

Comments
 (0)