From b18b3d00b7067c2ab092456b94e214e5c6c93711 Mon Sep 17 00:00:00 2001 From: Alexander Slobodeniuk Date: Thu, 28 Mar 2024 21:46:11 +0100 Subject: [PATCH] navigation: add missing sanity checks On practice a failure happened due to a race condition, the instance already have been freed, but it could also happen if the instance would be null. Instead of crashing this sanity check is a more suitable option, since with G_DEBUG=fatal-warnings it will crash too. Part-of: --- .../gst-libs/gst/video/navigation.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/subprojects/gst-plugins-base/gst-libs/gst/video/navigation.c b/subprojects/gst-plugins-base/gst-libs/gst/video/navigation.c index 09411ce0d2..8cf2154b74 100644 --- a/subprojects/gst-plugins-base/gst-libs/gst/video/navigation.c +++ b/subprojects/gst-plugins-base/gst-libs/gst/video/navigation.c @@ -93,8 +93,11 @@ gst_navigation_default_init (GstNavigationInterface * iface) void gst_navigation_send_event (GstNavigation * navigation, GstStructure * structure) { - GstNavigationInterface *iface = GST_NAVIGATION_GET_INTERFACE (navigation); + GstNavigationInterface *iface; + g_return_if_fail (GST_IS_NAVIGATION (navigation)); + + iface = GST_NAVIGATION_GET_INTERFACE (navigation); if (iface->send_event) { iface->send_event (navigation, structure); } else if (iface->send_event_simple) { @@ -116,6 +119,7 @@ void gst_navigation_send_key_event (GstNavigation * navigation, const char *event, const char *key) { + g_return_if_fail (GST_IS_NAVIGATION (navigation)); g_return_if_fail (g_strcmp0 (event, "key-press") == 0 || g_strcmp0 (event, "key-release") == 0); @@ -144,6 +148,7 @@ void gst_navigation_send_mouse_event (GstNavigation * navigation, const char *event, int button, double x, double y) { + g_return_if_fail (GST_IS_NAVIGATION (navigation)); g_return_if_fail (g_strcmp0 (event, "mouse-button-press") == 0 || g_strcmp0 (event, "mouse-button-release") == 0 || g_strcmp0 (event, "mouse-move") == 0); @@ -173,6 +178,8 @@ void gst_navigation_send_mouse_scroll_event (GstNavigation * navigation, double x, double y, double delta_x, double delta_y) { + g_return_if_fail (GST_IS_NAVIGATION (navigation)); + gst_navigation_send_event (navigation, gst_structure_new (GST_NAVIGATION_EVENT_NAME, "event", G_TYPE_STRING, "mouse-scroll", @@ -193,6 +200,8 @@ void gst_navigation_send_command (GstNavigation * navigation, GstNavigationCommand command) { + g_return_if_fail (GST_IS_NAVIGATION (navigation)); + gst_navigation_send_event (navigation, gst_structure_new (GST_NAVIGATION_EVENT_NAME, "event", G_TYPE_STRING, "command", "command-code", G_TYPE_UINT, (guint) command, NULL)); @@ -209,10 +218,12 @@ gst_navigation_send_command (GstNavigation * navigation, void gst_navigation_send_event_simple (GstNavigation * navigation, GstEvent * event) { - GstNavigationInterface *iface = GST_NAVIGATION_GET_INTERFACE (navigation); + GstNavigationInterface *iface; + g_return_if_fail (GST_IS_NAVIGATION (navigation)); g_return_if_fail (GST_EVENT_TYPE (event) == GST_EVENT_NAVIGATION); + iface = GST_NAVIGATION_GET_INTERFACE (navigation); if (iface->send_event_simple) { iface->send_event_simple (navigation, event); } else if (iface->send_event) {