Skip to content

Commit

Permalink
[media] media, cx231xx: Fix double free on close
Browse files Browse the repository at this point in the history
In cx231xx_v4l2_close() there are two calls to
cx231xx_release_resources(dev) followed by kfree(dev). That is a
problem since cx231xx_release_resources() already kfree()'s its
argument, so we end up doing a double free.

Easily resolved by just removing the redundant kfree() calls after the
calls to cx231xx_release_resources().

I also changed the 'dev = NULL' assignments (which are rather
pointless since 'dev' is about to go out of scope), to 'fh->dev = NULL'
since it looks to me that that is what was actually intended.
And I removed the 'dev = NULL' assignment at the end of
cx231xx_release_resources() since it is pointless.

Signed-off-by: Jesper Juhl <[email protected]>
Signed-off-by: Mauro Carvalho Chehab <[email protected]>
  • Loading branch information
jjuhl authored and Mauro Carvalho Chehab committed Mar 19, 2012
1 parent 1a611d8 commit 266e8ae
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 5 deletions.
1 change: 0 additions & 1 deletion drivers/media/video/cx231xx/cx231xx-cards.c
Original file line number Diff line number Diff line change
Expand Up @@ -861,7 +861,6 @@ void cx231xx_release_resources(struct cx231xx *dev)
kfree(dev->sliced_cc_mode.alt_max_pkt_size);
kfree(dev->ts1_mode.alt_max_pkt_size);
kfree(dev);
dev = NULL;
}

/*
Expand Down
6 changes: 2 additions & 4 deletions drivers/media/video/cx231xx/cx231xx-video.c
Original file line number Diff line number Diff line change
Expand Up @@ -2319,8 +2319,7 @@ static int cx231xx_v4l2_close(struct file *filp)
if (dev->state & DEV_DISCONNECTED) {
if (atomic_read(&dev->devlist_count) > 0) {
cx231xx_release_resources(dev);
kfree(dev);
dev = NULL;
fh->dev = NULL;
return 0;
}
return 0;
Expand Down Expand Up @@ -2350,8 +2349,7 @@ static int cx231xx_v4l2_close(struct file *filp)
free the remaining resources */
if (dev->state & DEV_DISCONNECTED) {
cx231xx_release_resources(dev);
kfree(dev);
dev = NULL;
fh->dev = NULL;
return 0;
}

Expand Down

0 comments on commit 266e8ae

Please sign in to comment.