Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

[media] media, cx231xx: Fix double free on close

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 <jj@chaosbits.net>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>

authored by

Jesper Juhl and committed by
Mauro Carvalho Chehab
266e8ae3 1a611d8c

+2 -5
-1
drivers/media/video/cx231xx/cx231xx-cards.c
··· 861 861 kfree(dev->sliced_cc_mode.alt_max_pkt_size); 862 862 kfree(dev->ts1_mode.alt_max_pkt_size); 863 863 kfree(dev); 864 - dev = NULL; 865 864 } 866 865 867 866 /*
+2 -4
drivers/media/video/cx231xx/cx231xx-video.c
··· 2319 2319 if (dev->state & DEV_DISCONNECTED) { 2320 2320 if (atomic_read(&dev->devlist_count) > 0) { 2321 2321 cx231xx_release_resources(dev); 2322 - kfree(dev); 2323 - dev = NULL; 2322 + fh->dev = NULL; 2324 2323 return 0; 2325 2324 } 2326 2325 return 0; ··· 2349 2350 free the remaining resources */ 2350 2351 if (dev->state & DEV_DISCONNECTED) { 2351 2352 cx231xx_release_resources(dev); 2352 - kfree(dev); 2353 - dev = NULL; 2353 + fh->dev = NULL; 2354 2354 return 0; 2355 2355 } 2356 2356