Skip to contentSkip to conversation

Fix a memory leak in em28xx_usb_probe()

PATCH In review Jesper Juhl 2 participants 2 messages Aug 9, 2007 – Aug 15, 2007 Media (V4L/DVB)

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Fix a memory leak in em28xx_usb_probe()

EHLO,

If, in em28xx_usb_probe() the memory allocation

	dev->alt_max_pkt_size = kmalloc(32*
						dev->num_alt,GFP_KERNEL);

fails, then we'll bail out and return -ENOMEM.
The problem is that in that case we don't free the storage allocated to 'dev', thus causing a memory leak.

This patch fixes the leak by freeing 'dev' before we return -ENOMEM. This fixes Coverity bug #647.

---

 drivers/media/video/em28xx/em28xx-video.c |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)
drivers/media/video/em28xx/em28xx-video.c +1 -0
index 2c7b158..40307f3 100644
@@ -1772,6 +1772,7 @@ static int em28xx_usb_probe(struct usb_interface *interface,
 	if (dev->alt_max_pkt_size == NULL) {
 		em28xx_errdev("out of memory!\n");
 		em28xx_devused&=~(1<<nr);
+		kfree(dev);
 		return -ENOMEM;
 	}
 
Acked-by on v1 1/1
#1 lore raw

Hi Jesper,

Quoted 9 lines · Jesper Juhl

EHLO,

If, in em28xx_usb_probe() the memory allocation

	dev->alt_max_pkt_size = kmalloc(32*
						dev->num_alt,GFP_KERNEL);

fails, then we'll bail out and return -ENOMEM.
The problem is that in that case we don't free the storage allocated to 'dev', thus causing a memory leak.

Quoted 5 lines

This patch fixes the leak by freeing 'dev' before we return -ENOMEM. This fixes Coverity bug #647.

thanks,
Markus

Quoted 23 lines

---

 drivers/media/video/em28xx/em28xx-video.c |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)
drivers/media/video/em28xx/em28xx-video.c +1 -0
index 2c7b158..40307f3 100644
@@ -1772,6 +1772,7 @@ static int em28xx_usb_probe(struct usb_interface
 *interface,
 	if (dev->alt_max_pkt_size == NULL) {
 		em28xx_errdev("out of memory!\n");
 		em28xx_devused&=~(1<<nr);
+		kfree(dev);
 		return -ENOMEM;
 	}
Signature · 1 line
Markus Rechberger