media: cpia2_usb: fix memory leaks
authorWenwen Wang <wenwen@cs.uga.edu>
Sat, 17 Aug 2019 05:27:46 +0000 (02:27 -0300)
committerMauro Carvalho Chehab <mchehab+samsung@kernel.org>
Mon, 26 Aug 2019 13:40:01 +0000 (10:40 -0300)
In submit_urbs(), 'cam->sbuf[i].data' is allocated through kmalloc_array().
However, it is not deallocated if the following allocation for urbs fails.
To fix this issue, free 'cam->sbuf[i].data' if usb_alloc_urb() fails.

Signed-off-by: Wenwen Wang <wenwen@cs.uga.edu>
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <mchehab+samsung@kernel.org>
drivers/media/usb/cpia2/cpia2_usb.c

index 17468f7..3ab80a7 100644 (file)
@@ -676,6 +676,10 @@ static int submit_urbs(struct camera_data *cam)
                if (!urb) {
                        for (j = 0; j < i; j++)
                                usb_free_urb(cam->sbuf[j].urb);
+                       for (j = 0; j < NUM_SBUF; j++) {
+                               kfree(cam->sbuf[j].data);
+                               cam->sbuf[j].data = NULL;
+                       }
                        return -ENOMEM;
                }