From cd6d2eb9b6795cb12c875435c1de70173d888b15 Mon Sep 17 00:00:00 2001 From: fryshorts Date: Mon, 11 Aug 2014 23:35:13 +0200 Subject: [PATCH] Fix crash in v4l2 plugin. This adds checks to make sure munmap and bfree are only called when there was actually memory mapped and allocated. --- plugins/linux-v4l2/v4l2-helpers.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/plugins/linux-v4l2/v4l2-helpers.c b/plugins/linux-v4l2/v4l2-helpers.c index 165f26502..6497ff1cc 100644 --- a/plugins/linux-v4l2/v4l2-helpers.c +++ b/plugins/linux-v4l2/v4l2-helpers.c @@ -111,12 +111,14 @@ int_fast32_t v4l2_create_mmap(int_fast32_t dev, struct v4l2_buffer_data *buf) int_fast32_t v4l2_destroy_mmap(struct v4l2_buffer_data *buf) { for(uint_fast32_t i = 0; i < buf->count; ++i) { - if (buf->info[i].start != MAP_FAILED) + if (buf->info[i].start != MAP_FAILED && buf->info[i].start != 0) v4l2_munmap(buf->info[i].start, buf->info[i].length); } - buf->count = 0; - bfree(buf->info); + if (buf->count) { + bfree(buf->info); + buf->count = 0; + } return 0; }