mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-01-03 14:08:56 +00:00
gl/context/cocoa: ensure pixel format lives as long as the context
Under some circumstances, the CGLPixelFormatObj was being destroyed too early which could lead to potential use-after-frees. Fix by returning a reference when asked for the pixel format. Fixes: https://gitlab.freedesktop.org/gstreamer/gstreamer/-/issues/3154 Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/6504>
This commit is contained in:
parent
ed54734825
commit
49a7424d1e
1 changed files with 10 additions and 1 deletions
|
@ -170,7 +170,9 @@ gst_gl_context_cocoa_dump_pixel_format (CGLPixelFormatObj fmt)
|
||||||
CGLPixelFormatObj
|
CGLPixelFormatObj
|
||||||
gst_gl_context_cocoa_get_pixel_format (GstGLContextCocoa *context)
|
gst_gl_context_cocoa_get_pixel_format (GstGLContextCocoa *context)
|
||||||
{
|
{
|
||||||
return context->priv->pixel_format;
|
if (context->priv->pixel_format)
|
||||||
|
return CGLRetainPixelFormat (context->priv->pixel_format);
|
||||||
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static GstStructure *
|
static GstStructure *
|
||||||
|
@ -262,6 +264,7 @@ gst_gl_context_cocoa_create_context (GstGLContext *context, GstGLAPI gl_api,
|
||||||
gint profile;
|
gint profile;
|
||||||
|
|
||||||
fmt = CGLGetPixelFormat (priv->external_gl_context);
|
fmt = CGLGetPixelFormat (priv->external_gl_context);
|
||||||
|
CGLRetainPixelFormat (fmt);
|
||||||
|
|
||||||
#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1070
|
#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1070
|
||||||
/* core profile is only available in >= 10.7 */
|
/* core profile is only available in >= 10.7 */
|
||||||
|
@ -307,6 +310,7 @@ gst_gl_context_cocoa_create_context (GstGLContext *context, GstGLAPI gl_api,
|
||||||
if (ret != kCGLNoError) {
|
if (ret != kCGLNoError) {
|
||||||
g_set_error (error, GST_GL_CONTEXT_ERROR, GST_GL_CONTEXT_ERROR_CREATE_CONTEXT,
|
g_set_error (error, GST_GL_CONTEXT_ERROR, GST_GL_CONTEXT_ERROR_CREATE_CONTEXT,
|
||||||
"failed to create context: %s", CGLErrorString (ret));
|
"failed to create context: %s", CGLErrorString (ret));
|
||||||
|
CGLReleasePixelFormat (fmt);
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -358,6 +362,11 @@ gst_gl_context_cocoa_destroy_context (GstGLContext *context)
|
||||||
CGLDestroyContext(context_cocoa->priv->gl_context);
|
CGLDestroyContext(context_cocoa->priv->gl_context);
|
||||||
context_cocoa->priv->gl_context = NULL;
|
context_cocoa->priv->gl_context = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (context_cocoa->priv->pixel_format) {
|
||||||
|
CGLReleasePixelFormat(context_cocoa->priv->pixel_format);
|
||||||
|
context_cocoa->priv->pixel_format = NULL;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static guintptr
|
static guintptr
|
||||||
|
|
Loading…
Reference in a new issue