Skip to content

Commit

Permalink
media: dvb-core: fix a memory leak bug
Browse files Browse the repository at this point in the history
In dvb_create_media_entity(), 'dvbdev->entity' is allocated through
kzalloc(). Then, 'dvbdev->pads' is allocated through kcalloc(). However, if
kcalloc() fails, the allocated 'dvbdev->entity' is not deallocated, leading
to a memory leak bug. To fix this issue, free 'dvbdev->entity' before
returning -ENOMEM.

Signed-off-by: Wenwen Wang <wenwen@cs.uga.edu>
Signed-off-by: Sean Young <sean@mess.org>
Signed-off-by: Mauro Carvalho Chehab <mchehab+samsung@kernel.org>
  • Loading branch information
wenwenwang1 authored and mchehab committed Aug 21, 2019
1 parent b1da86f commit fcd5ce4
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion drivers/media/dvb-core/dvbdev.c
Original file line number Diff line number Diff line change
Expand Up @@ -339,8 +339,10 @@ static int dvb_create_media_entity(struct dvb_device *dvbdev,
if (npads) {
dvbdev->pads = kcalloc(npads, sizeof(*dvbdev->pads),
GFP_KERNEL);
if (!dvbdev->pads)
if (!dvbdev->pads) {
kfree(dvbdev->entity);
return -ENOMEM;
}
}

switch (type) {
Expand Down

0 comments on commit fcd5ce4

Please sign in to comment.