Skip to content

Commit de095b1

Browse files
committed
gstelement: improve locking around hash usage
Protect access of pad_hash, numpads and numpads_use_hash under the object lock.
1 parent 524e49e commit de095b1

File tree

1 file changed

+1
-6
lines changed

1 file changed

+1
-6
lines changed

subprojects/gstreamer/gst/gstelement.c

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -770,13 +770,12 @@ gst_element_add_pad (GstElement * element, GstPad * pad)
770770
GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_NEED_PARENT);
771771
GST_OBJECT_UNLOCK (pad);
772772

773+
GST_OBJECT_LOCK (element);
773774
/* Check whether we need to switch to using the hash */
774775
if ((element->pads_hash == NULL) &&
775776
(element->numpads_use_hash >= 0) &&
776777
(element->numpads + 1) >= (element->numpads_use_hash)) {
777778

778-
GST_OBJECT_LOCK (element);
779-
780779
/* Time to switch to using the hash */
781780
element->pads_hash = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
782781

@@ -787,13 +786,9 @@ gst_element_add_pad (GstElement * element, GstPad * pad)
787786
child_pad = GST_PAD_CAST (walk->data);
788787
g_hash_table_insert (element->pads_hash, g_strdup (GST_PAD_NAME(child_pad)), child_pad);
789788
}
790-
791-
GST_OBJECT_UNLOCK (element);
792789
}
793790

794791
/* then check to see if there's already a pad by that name here */
795-
GST_OBJECT_LOCK (element);
796-
797792
if (!GST_OBJECT_FLAG_IS_SET (element, GST_ELEMENT_FLAG_NO_UNIQUE_CHECK)) {
798793
if (element->pads_hash != NULL) {
799794
/* Use the hash table to look up whether we already have an pad with that

0 commit comments

Comments
 (0)