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.
master
fryshorts 2014-08-11 23:35:13 +02:00
parent d73d2b22f8
commit cd6d2eb9b6
1 changed files with 5 additions and 3 deletions

View File

@ -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;
}