diff --git a/gst-libs/gst/pbutils/install-plugins.c b/gst-libs/gst/pbutils/install-plugins.c index e87d972601..7ca19deebe 100644 --- a/gst-libs/gst/pbutils/install-plugins.c +++ b/gst-libs/gst/pbutils/install-plugins.c @@ -366,6 +366,8 @@ #include #endif +#include + /* best effort to make things compile and possibly even work on win32 */ #ifndef WEXITSTATUS # define WEXITSTATUS(status) ((((guint)(status)) & 0xff00) >> 8) @@ -489,6 +491,18 @@ gst_install_plugins_get_helper (void) return helper; } +static gboolean +ptr_array_contains_string (GPtrArray * arr, const gchar * s) +{ + gint i; + + for (i = 0; i < arr->len; ++i) { + if (strcmp ((const char *) g_ptr_array_index (arr, i), s) == 0) + return TRUE; + } + return FALSE; +} + static gboolean gst_install_plugins_spawn_child (gchar ** details, GstInstallPluginsContext * ctx, GPid * child_pid, gint * exit_status) @@ -509,9 +523,10 @@ gst_install_plugins_spawn_child (gchar ** details, g_ptr_array_add (arr, xid_str); } - /* finally, add the detail strings */ + /* finally, add the detail strings, but without duplicates */ while (details != NULL && details[0] != NULL) { - g_ptr_array_add (arr, details[0]); + if (!ptr_array_contains_string (arr, details[0])) + g_ptr_array_add (arr, details[0]); ++details; } diff --git a/tests/check/libs/pbutils.c b/tests/check/libs/pbutils.c index a07858113e..61b8b60979 100644 --- a/tests/check/libs/pbutils.c +++ b/tests/check/libs/pbutils.c @@ -549,6 +549,7 @@ GST_START_TEST (test_pb_utils_install_plugins) GstInstallPluginsContext *ctx; GstInstallPluginsReturn ret; gchar *details[] = { "detail1", "detail2", NULL }; + gchar *details_multi[] = { "detail1", "detail1", "detail2", NULL }; ctx = gst_install_plugins_context_new (); @@ -583,6 +584,15 @@ GST_START_TEST (test_pb_utils_install_plugins) test_pb_utils_install_plugins_do_callout (details, ctx, SCRIPT_WITH_XID, GST_INSTALL_PLUGINS_SUCCESS); + /* and make sure that duplicate detail strings get dropped */ + test_pb_utils_install_plugins_do_callout (details_multi, NULL, SCRIPT_NO_XID, + GST_INSTALL_PLUGINS_NOT_FOUND); + + /* and the same again with context */ + gst_install_plugins_context_set_xid (ctx, 42); + test_pb_utils_install_plugins_do_callout (details_multi, ctx, SCRIPT_WITH_XID, + GST_INSTALL_PLUGINS_SUCCESS); + /* and free the context now that we don't need it any longer */ gst_install_plugins_context_free (ctx);