diff options
author | He Junyan <junyan.he@intel.com> | 2020-11-04 23:05:27 +0800 |
---|---|---|
committer | Sebastian Dröge <sebastian@centricular.com> | 2020-12-04 10:05:56 +0200 |
commit | b5bd6b6f7897242154e05922164a2af71910a77d (patch) | |
tree | b5b93f64a67a66a0e1ce2ca7fb421cd994c89c9b | |
parent | ee38a96c83661ab58a1a61196a6c6ae875393e28 (diff) | |
download | gstreamer-plugins-base-b5bd6b6f7897242154e05922164a2af71910a77d.tar.gz |
gluploadelement: Avoid race condition in propose_allocation().
The inside upload and context may have race condition in the function
of propose_allocation(). They may be destroyed while this function is
stilling using it.
Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-base/-/merge_requests/921>
-rw-r--r-- | ext/gl/gstgluploadelement.c | 23 |
1 files changed, 18 insertions, 5 deletions
diff --git a/ext/gl/gstgluploadelement.c b/ext/gl/gstgluploadelement.c index fab026bb6..a4d16501f 100644 --- a/ext/gl/gstgluploadelement.c +++ b/ext/gl/gstgluploadelement.c @@ -209,19 +209,32 @@ _gst_gl_upload_element_propose_allocation (GstBaseTransform * bt, GstQuery * decide_query, GstQuery * query) { GstGLUploadElement *upload = GST_GL_UPLOAD_ELEMENT (bt); - GstGLContext *context = GST_GL_BASE_FILTER (bt)->context; + GstGLUpload *ul; + GstGLContext *context; gboolean ret; - if (!upload->upload) + GST_OBJECT_LOCK (upload); + if (!upload->upload) { + GST_OBJECT_UNLOCK (upload); return FALSE; - if (!context) + } + ul = gst_object_ref (upload->upload); + GST_OBJECT_UNLOCK (upload); + + context = gst_gl_base_filter_get_gl_context (GST_GL_BASE_FILTER (bt)); + if (!context) { + gst_object_unref (ul); return FALSE; + } - gst_gl_upload_set_context (upload->upload, context); + gst_gl_upload_set_context (ul, context); ret = GST_BASE_TRANSFORM_CLASS (parent_class)->propose_allocation (bt, decide_query, query); - gst_gl_upload_propose_allocation (upload->upload, decide_query, query); + gst_gl_upload_propose_allocation (ul, decide_query, query); + + gst_object_unref (ul); + gst_object_unref (context); return ret; } |