diff options
author | Mark Thompson <sw@jkqxz.net> | 2018-01-10 01:56:41 +0300 |
---|---|---|
committer | Mark Thompson <sw@jkqxz.net> | 2018-01-21 03:37:35 +0300 |
commit | a0c624e299730c8c5800375c2f5f3c6c200053ff (patch) | |
tree | 6a7b9312d0b25d9a65d160d62165675d4985bdfb /libavcodec/v4l2_buffers.h | |
parent | 6c1c6c6c71fc776c6dd25d13861b036dad2cdc1b (diff) |
avcodec: v4l2_m2m: fix races around freeing data on close
Refcount all of the context information. This also fixes a potential
segmentation fault when accessing freed memory (buffer returned after
the codec has been closed).
Tested-by: Jorge Ramirez-Ortiz <jorge.ramirez.ortiz@gmail.com>
Diffstat (limited to 'libavcodec/v4l2_buffers.h')
-rw-r--r-- | libavcodec/v4l2_buffers.h | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/libavcodec/v4l2_buffers.h b/libavcodec/v4l2_buffers.h index e28a4a650d..dc5cc9e267 100644 --- a/libavcodec/v4l2_buffers.h +++ b/libavcodec/v4l2_buffers.h @@ -24,6 +24,7 @@ #ifndef AVCODEC_V4L2_BUFFERS_H #define AVCODEC_V4L2_BUFFERS_H +#include <stdatomic.h> #include <linux/videodev2.h> #include "avcodec.h" @@ -41,6 +42,11 @@ typedef struct V4L2Buffer { /* each buffer needs to have a reference to its context */ struct V4L2Context *context; + /* This object is refcounted per-plane, so we need to keep track + * of how many context-refs we are holding. */ + AVBufferRef *context_ref; + atomic_uint context_refcount; + /* keep track of the mmap address and mmap length */ struct V4L2Plane_info { int bytesperline; |