Commit 4b065060 authored by Colin Ian King's avatar Colin Ian King Committed by Mauro Carvalho Chehab
Browse files

media: uvcvideo: Fix memory leak of object map on error exit path



Currently when the allocation of map->name fails the error exit path
does not kfree the previously allocated object map. Fix this by
setting ret to -ENOMEM and taking the free_map exit error path to
ensure map is kfree'd.

Addresses-Coverity: ("Resource leak")

Fixes: 70fa906d ("media: uvcvideo: Use control names from framework")
Signed-off-by: default avatarColin Ian King <colin.king@canonical.com>
Reviewed-by: default avatarRicardo Ribalda <ribalda@chromium.org>
Signed-off-by: default avatarLaurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab+huawei@kernel.org>
parent 4383cfa1
Loading
Loading
Loading
Loading
+4 −2
Original line number Diff line number Diff line
@@ -44,8 +44,10 @@ static int uvc_ioctl_ctrl_map(struct uvc_video_chain *chain,
	if (v4l2_ctrl_get_name(map->id) == NULL) {
		map->name = kmemdup(xmap->name, sizeof(xmap->name),
				    GFP_KERNEL);
		if (!map->name)
			return -ENOMEM;
		if (!map->name) {
			ret = -ENOMEM;
			goto free_map;
		}
	}
	memcpy(map->entity, xmap->entity, sizeof(map->entity));
	map->selector = xmap->selector;