Skip to content
Snippets Groups Projects
Commit b8973cf8 authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont
Browse files

v4l2: allocate buffer array separately

The array may be reallocated later on, so it ought to be allocated
separately from its container.
parent 58303ae1
No related branches found
No related tags found
1 merge request!1890v4l2: buffer clean up and fixes
......@@ -87,8 +87,10 @@ static void ReleaseBuffer(block_t *block)
v4l2_munmap(block->p_start, block->i_size);
if (vlc_popcount(mask) == 1) /* last active buffer? */
if (vlc_popcount(mask) == 1) { /* last active buffer? */
free(pool->bufs);
free(pool);
}
}
static const struct vlc_block_callbacks vlc_v4l2_buffer_cbs = {
......@@ -167,10 +169,16 @@ struct vlc_v4l2_buffers *StartMmap(vlc_object_t *obj, int fd)
return NULL;
}
pool = malloc(sizeof (*pool) + req.count * sizeof (pool->bufs[0]));
pool = malloc(sizeof (*pool));
if (unlikely(pool == NULL))
return NULL;
pool->bufs = calloc(req.count, sizeof (pool->bufs[0]));
if (unlikely(pool->bufs == NULL)) {
free(pool);
return NULL;
}
pool->fd = fd;
pool->inflight = 0;
pool->count = 0;
......
......@@ -45,11 +45,12 @@ struct vlc_v4l2_buffer {
};
struct vlc_v4l2_buffers {
size_t count;
struct vlc_v4l2_buffer *bufs;
int fd;
_Atomic uint32_t inflight;
vlc_mutex_t lock;
size_t count;
struct vlc_v4l2_buffer bufs[];
};
/* v4l2.c */
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment