media: v4l2-mem2mem: fix a memleak in v4l2_m2m_register_entity

The entity->name (i.e. name) is allocated in v4l2_m2m_register_entity
but isn't freed in its following error-handling paths. This patch
adds such deallocation to prevent memleak of entity->name.

Fixes: be2fff6563 ("media: add helpers for memory-to-memory media controller")
Signed-off-by: Zhipeng Lu <alexious@zju.edu.cn>
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
This commit is contained in:
Zhipeng Lu 2024-02-01 20:48:44 +08:00 committed by Hans Verkuil
parent 8cf9c50510
commit 8f94b49a5b

View File

@ -1087,11 +1087,17 @@ static int v4l2_m2m_register_entity(struct media_device *mdev,
entity->function = function;
ret = media_entity_pads_init(entity, num_pads, pads);
if (ret)
if (ret) {
kfree(entity->name);
entity->name = NULL;
return ret;
}
ret = media_device_register_entity(mdev, entity);
if (ret)
if (ret) {
kfree(entity->name);
entity->name = NULL;
return ret;
}
return 0;
}