From 73a03b3571e14233232494f301303ebba14957dc Mon Sep 17 00:00:00 2001 From: Laurent Pinchart Date: Tue, 22 May 2018 10:20:35 +0300 Subject: v4l2: Fail v4l2_alloc_buffers() when buffers are already allocated Allocating buffers allocates resources that must be explicitly freed. Calling v4l2_alloc_buffers() a second time without freeing the buffers in between causes memory leaks and must not be allowed. Signed-off-by: Laurent Pinchart --- v4l2.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/v4l2.c b/v4l2.c index 3baf55b..8d5e847 100644 --- a/v4l2.c +++ b/v4l2.c @@ -510,6 +510,9 @@ int v4l2_alloc_buffers(struct v4l2_device *dev, enum v4l2_memory memtype, unsigned int i; int ret; + if (dev->nbufs != 0) + return -EBUSY; + /* Request the buffers from the driver. */ memset(&rb, 0, sizeof rb); rb.count = nbufs; -- cgit v1.2.3