Skip to contentSkip to conversation

videobuf2-dma-sg: fix possible memory leak

PATCH New Geyslan G. Bem 1 participant 1 message Nov 20, 2013 Media (V4L/DVB)

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 videobuf2-dma-sg: fix possible memory leak

Fix the return when 'buf->pages' allocation error.

---
 drivers/media/v4l2-core/videobuf2-dma-sg.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/media/v4l2-core/videobuf2-dma-sg.c +2 -1
index 2f86054..0d3a8ff 100644
@@ -178,7 +178,7 @@ static void *vb2_dma_sg_get_userptr(void *alloc_ctx, unsigned long vaddr,
 	buf->pages = kzalloc(buf->num_pages * sizeof(struct page *),
 			     GFP_KERNEL);
 	if (!buf->pages)
-		return NULL;
+		goto userptr_fail_alloc_pages;
 
 	num_pages_from_user = get_user_pages(current, current->mm,
 					     vaddr & PAGE_MASK,
@@ -204,6 +204,7 @@ userptr_fail_get_user_pages:
 	while (--num_pages_from_user >= 0)
 		put_page(buf->pages[num_pages_from_user]);
 	kfree(buf->pages);
+userptr_fail_alloc_pages:
 	kfree(buf);
 	return NULL;
 }
Signature · 1 line
1.8.4.2