Browse Source

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.
fryshorts 11 years ago
parent
commit
cd6d2eb9b6
1 changed files with 5 additions and 3 deletions
  1. 5 3
      plugins/linux-v4l2/v4l2-helpers.c

+ 5 - 3
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;
 }