osxaudio: Avoid dangling pointer on shutdown

When tearing down the elements we were still referring to the ringbuffer unique_id
as our property while it was already freed, leading to potential segfaults when
accessing the property.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/7426>
This commit is contained in:
Thibault Saunier 2024-08-29 12:10:23 -04:00 committed by GStreamer Marge Bot
parent 4802ad8eb6
commit 3506f5fb07
2 changed files with 22 additions and 0 deletions

View file

@ -248,6 +248,12 @@ gst_osx_audio_sink_change_state (GstElement * element,
GstStateChangeReturn ret; GstStateChangeReturn ret;
switch (transition) { switch (transition) {
case GST_STATE_CHANGE_READY_TO_NULL:
GST_OBJECT_LOCK (osxsink);
osxsink->device_id = kAudioDeviceUnknown;
osxsink->unique_id = NULL;
GST_OBJECT_UNLOCK (osxsink);
break;
default: default:
break; break;
} }
@ -265,8 +271,10 @@ gst_osx_audio_sink_change_state (GstElement * element,
ringbuffer = ringbuffer =
GST_OSX_AUDIO_RING_BUFFER (GST_AUDIO_BASE_SINK (osxsink)->ringbuffer); GST_OSX_AUDIO_RING_BUFFER (GST_AUDIO_BASE_SINK (osxsink)->ringbuffer);
if (ringbuffer->core_audio->device_id != osxsink->device_id) { if (ringbuffer->core_audio->device_id != osxsink->device_id) {
GST_OBJECT_LOCK (osxsink);
osxsink->device_id = ringbuffer->core_audio->device_id; osxsink->device_id = ringbuffer->core_audio->device_id;
osxsink->unique_id = ringbuffer->core_audio->unique_id; osxsink->unique_id = ringbuffer->core_audio->unique_id;
GST_OBJECT_UNLOCK (osxsink);
g_object_notify (G_OBJECT (osxsink), "device"); g_object_notify (G_OBJECT (osxsink), "device");
} }
break; break;
@ -290,7 +298,9 @@ gst_osx_audio_sink_get_property (GObject * object, guint prop_id,
g_value_set_int (value, sink->device_id); g_value_set_int (value, sink->device_id);
break; break;
case ARG_UNIQUE_ID: case ARG_UNIQUE_ID:
GST_OBJECT_LOCK (sink);
g_value_set_string (value, sink->unique_id); g_value_set_string (value, sink->unique_id);
GST_OBJECT_UNLOCK (sink);
break; break;
#endif #endif
case ARG_VOLUME: case ARG_VOLUME:

View file

@ -207,7 +207,9 @@ gst_osx_audio_src_get_property (GObject * object, guint prop_id,
g_value_set_int (value, src->device_id); g_value_set_int (value, src->device_id);
break; break;
case ARG_UNIQUE_ID: case ARG_UNIQUE_ID:
GST_OBJECT_LOCK (src);
g_value_set_string (value, src->unique_id); g_value_set_string (value, src->unique_id);
GST_OBJECT_UNLOCK (src);
break; break;
default: default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
@ -223,6 +225,13 @@ gst_osx_audio_src_change_state (GstElement * element, GstStateChange transition)
GstStateChangeReturn ret; GstStateChangeReturn ret;
switch (transition) { switch (transition) {
case GST_STATE_CHANGE_READY_TO_NULL:{
GST_OBJECT_LOCK (osxsrc);
osxsrc->device_id = kAudioDeviceUnknown;
osxsrc->unique_id = NULL;
GST_OBJECT_UNLOCK (osxsrc);
break;
}
default: default:
break; break;
} }
@ -237,8 +246,11 @@ gst_osx_audio_src_change_state (GstElement * element, GstStateChange transition)
ringbuffer = ringbuffer =
GST_OSX_AUDIO_RING_BUFFER (GST_AUDIO_BASE_SRC (osxsrc)->ringbuffer); GST_OSX_AUDIO_RING_BUFFER (GST_AUDIO_BASE_SRC (osxsrc)->ringbuffer);
if (ringbuffer->core_audio->device_id != osxsrc->device_id) { if (ringbuffer->core_audio->device_id != osxsrc->device_id) {
GST_OBJECT_LOCK (osxsrc);
osxsrc->device_id = ringbuffer->core_audio->device_id; osxsrc->device_id = ringbuffer->core_audio->device_id;
osxsrc->unique_id = ringbuffer->core_audio->unique_id; osxsrc->unique_id = ringbuffer->core_audio->unique_id;
GST_OBJECT_UNLOCK (osxsrc);
g_object_notify (G_OBJECT (osxsrc), "device"); g_object_notify (G_OBJECT (osxsrc), "device");
} }
break; break;