kernel: userspace: Fix memory leak in dynamic_object_create

If memory allocation for a dynamic object fails, an attempt is made to free
a null pointer instead of the allocated element of the dynamic object list.

Signed-off-by: Adrian Warecki <adrian.warecki@intel.com>
This commit is contained in:
Adrian Warecki 2025-05-14 17:49:50 +02:00 committed by Fabio Baltieri
commit 042bf2c3fa

View file

@ -364,7 +364,7 @@ static struct k_object *dynamic_object_create(enum k_objects otype, size_t align
} else {
dyn->data = z_thread_aligned_alloc(align, obj_size_get(otype) + size);
if (dyn->data == NULL) {
k_free(dyn->data);
k_free(dyn);
return NULL;
}
dyn->kobj.name = dyn->data;