From 9b242594bfe0256419d5cf2b0701d2997beccc8b Mon Sep 17 00:00:00 2001 From: Laurent Pinchart Date: Mon, 11 Jul 2011 22:09:29 +0200 Subject: Free userspace buffers when freeing video buffers Memory allocated with posix_memalign() must be freed with free(). Signed-off-by: Laurent Pinchart --- yavta.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/yavta.c b/yavta.c index 8e9ecc4..5328a1b 100644 --- a/yavta.c +++ b/yavta.c @@ -425,14 +425,25 @@ static int video_free_buffers(struct device *dev) if (dev->nbufs == 0) return 0; - if (dev->memtype == V4L2_MEMORY_MMAP) { - for (i = 0; i < dev->nbufs; ++i) { + for (i = 0; i < dev->nbufs; ++i) { + switch (dev->memtype) { + case V4L2_MEMORY_MMAP: ret = munmap(dev->buffers[i].mem, dev->buffers[i].size); if (ret < 0) { printf("Unable to unmap buffer %u (%d)\n", i, errno); return ret; } + break; + + case V4L2_MEMORY_USERPTR: + free(dev->buffers[i].mem); + break; + + default: + break; } + + dev->buffers[i].mem = NULL; } memset(&rb, 0, sizeof rb); -- cgit v1.2.3