Skip to content

Commit ade9596

Browse files
Fix: deinitialization of the shared plugin crash (#1114)
Fix gst mtl shared plugin deinitialization function naive approach to the plugins in the shared pipline space, making sure the plugins cannot abuse the shared counter by reseting their handle to NULL>
1 parent d084055 commit ade9596

File tree

8 files changed

+26
-17
lines changed

8 files changed

+26
-17
lines changed

ecosystem/gstreamer_plugin/gst_mtl_common.c

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -659,6 +659,8 @@ mtl_handle gst_mtl_common_init_handle(GeneralArgs* general_args,
659659
}
660660

661661
common_handle.mtl_handle_reference_count++;
662+
GST_INFO("MTL shared handle reference count incremented to: %d",
663+
common_handle.mtl_handle_reference_count);
662664
common_handle.mtl_handle = handle;
663665
pthread_mutex_unlock(&common_handle.mutex);
664666
return common_handle.mtl_handle;
@@ -669,11 +671,8 @@ mtl_handle gst_mtl_common_init_handle(GeneralArgs* general_args,
669671
* If the handle is the shared handle, the reference count is decremented.
670672
* If the reference count reaches zero, the handle is deinitialized.
671673
* If the handle is not the shared handle, it is deinitialized immediately.
672-
*
673-
* @param handle MTL handle to deinitialize (Null is an acceptable value then
674-
* shared value will be used).
675674
*/
676-
gint gst_mtl_common_deinit_handle(mtl_handle handle) {
675+
gint gst_mtl_common_deinit_handle(mtl_handle* handle) {
677676
gint ret;
678677

679678
if (!handle) {
@@ -682,23 +681,33 @@ gint gst_mtl_common_deinit_handle(mtl_handle handle) {
682681
}
683682

684683
pthread_mutex_lock(&common_handle.mutex);
685-
if (handle == common_handle.mtl_handle) {
684+
685+
if (*handle == common_handle.mtl_handle) {
686686
common_handle.mtl_handle_reference_count--;
687687

688688
if (common_handle.mtl_handle_reference_count > 0) {
689+
GST_INFO("Shared handle is still in use, reference count: %d",
690+
common_handle.mtl_handle_reference_count);
689691
pthread_mutex_unlock(&common_handle.mutex);
690692
return 0;
693+
} else if (common_handle.mtl_handle_reference_count < 0) {
694+
GST_ERROR("Invalid reference count: %d", common_handle.mtl_handle_reference_count);
695+
pthread_mutex_unlock(&common_handle.mutex);
696+
return -EINVAL;
691697
}
698+
699+
GST_INFO("Deinitializing shared handle");
692700
}
693701

694-
ret = mtl_stop(handle);
702+
ret = mtl_stop(*handle);
695703
if (ret) {
696704
GST_ERROR("Failed to stop MTL library");
697705
pthread_mutex_unlock(&common_handle.mutex);
698706
return ret;
699707
}
700708

701-
ret = mtl_uninit(handle);
709+
ret = mtl_uninit(*handle);
710+
*handle = NULL;
702711
pthread_mutex_unlock(&common_handle.mutex);
703712
return ret;
704713
}

ecosystem/gstreamer_plugin/gst_mtl_common.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,9 @@ typedef struct GeneralArgs {
6767
} GeneralArgs;
6868

6969
typedef struct SessionPortArgs {
70-
gchar session_ip_string[MTL_PORT_MAX][MTL_PORT_MAX_LEN];
71-
gchar port[MTL_PORT_MAX][MTL_PORT_MAX_LEN];
72-
gint udp_port[MTL_PORT_MAX];
70+
gchar session_ip_string[2][MTL_PORT_MAX_LEN];
71+
gchar port[2][MTL_PORT_MAX_LEN];
72+
gint udp_port[2];
7373
gint payload_type;
7474
} SessionPortArgs;
7575

@@ -108,5 +108,5 @@ void gst_mtl_common_get_general_arguments(GObject* object, guint prop_id,
108108
mtl_handle gst_mtl_common_init_handle(GeneralArgs* generalArgs,
109109
gboolean force_to_initialize_new_instance);
110110

111-
gint gst_mtl_common_deinit_handle(mtl_handle handle);
111+
gint gst_mtl_common_deinit_handle(mtl_handle* handle);
112112
#endif /* __GST_MTL_COMMON_H__ */

ecosystem/gstreamer_plugin/gst_mtl_st20p_rx.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -495,7 +495,7 @@ static void gst_mtl_st20p_rx_finalize(GObject* object) {
495495
}
496496

497497
if (src->mtl_lib_handle) {
498-
if (gst_mtl_common_deinit_handle(src->mtl_lib_handle)) {
498+
if (gst_mtl_common_deinit_handle(&src->mtl_lib_handle)) {
499499
GST_ERROR("Failed to uninitialize MTL library");
500500
return;
501501
}

ecosystem/gstreamer_plugin/gst_mtl_st20p_tx.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -482,7 +482,7 @@ static void gst_mtl_st20p_tx_finalize(GObject* object) {
482482
}
483483

484484
if (sink->mtl_lib_handle) {
485-
if (gst_mtl_common_deinit_handle(sink->mtl_lib_handle))
485+
if (gst_mtl_common_deinit_handle(&sink->mtl_lib_handle))
486486
GST_ERROR("Failed to uninitialize MTL library");
487487
}
488488
}

ecosystem/gstreamer_plugin/gst_mtl_st30p_rx.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -464,7 +464,7 @@ static void gst_mtl_st30p_rx_finalize(GObject* object) {
464464
}
465465

466466
if (src->mtl_lib_handle) {
467-
if (gst_mtl_common_deinit_handle(src->mtl_lib_handle)) {
467+
if (gst_mtl_common_deinit_handle(&src->mtl_lib_handle)) {
468468
GST_ERROR("Failed to uninitialize MTL library");
469469
return;
470470
}

ecosystem/gstreamer_plugin/gst_mtl_st30p_tx.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -535,7 +535,7 @@ static void gst_mtl_st30p_tx_finalize(GObject* object) {
535535
}
536536

537537
if (sink->mtl_lib_handle) {
538-
if (gst_mtl_common_deinit_handle(sink->mtl_lib_handle))
538+
if (gst_mtl_common_deinit_handle(&sink->mtl_lib_handle))
539539
GST_ERROR("Failed to uninitialize MTL library");
540540
}
541541
}

ecosystem/gstreamer_plugin/gst_mtl_st40_rx.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -485,7 +485,7 @@ static void gst_mtl_st40_rx_finalize(GObject* object) {
485485
pthread_cond_destroy(&src->mbuff_cond);
486486

487487
if (src->mtl_lib_handle) {
488-
if (gst_mtl_common_deinit_handle(src->mtl_lib_handle)) {
488+
if (gst_mtl_common_deinit_handle(&src->mtl_lib_handle)) {
489489
GST_ERROR("Failed to uninitialize MTL library");
490490
}
491491
}

ecosystem/gstreamer_plugin/gst_mtl_st40p_tx.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,7 @@ static void gst_mtl_st40p_tx_finalize(GObject* object) {
460460
}
461461

462462
if (sink->mtl_lib_handle) {
463-
if (gst_mtl_common_deinit_handle(sink->mtl_lib_handle)) {
463+
if (gst_mtl_common_deinit_handle(&sink->mtl_lib_handle)) {
464464
GST_ERROR("Failed to uninitialize MTL library");
465465
return;
466466
}

0 commit comments

Comments
 (0)