From 00b4bfa48f23e671b40c36e428ebfc224f0e3c9c Mon Sep 17 00:00:00 2001 From: Alessandro Decina Date: Thu, 19 Aug 2010 15:10:25 +0200 Subject: gnlcomposition: fail early in remove_object when removing an invalid object. Make gnl_composition_remove_object return immediately FALSE when removing an object not contained in the composition. --- gnl/gnlcomposition.c | 15 +++++++++------ tests/check/gnl/gnlcomposition.c | 20 ++++++++++++++++++++ 2 files changed, 29 insertions(+), 6 deletions(-) diff --git a/gnl/gnlcomposition.c b/gnl/gnlcomposition.c index 1c4e62d..fe16f6d 100644 --- a/gnl/gnlcomposition.c +++ b/gnl/gnlcomposition.c @@ -2609,6 +2609,12 @@ gnl_composition_remove_object (GstBin * bin, GstElement * element) COMP_OBJECTS_LOCK (comp); + entry = COMP_ENTRY (comp, element); + if (entry == NULL) { + COMP_OBJECTS_UNLOCK (comp); + goto out; + } + gst_object_ref (element); gst_element_set_locked_state (element, FALSE); @@ -2629,8 +2635,7 @@ gnl_composition_remove_object (GstBin * bin, GstElement * element) GST_LOG_OBJECT (element, "Removed from the objects start/stop list"); } - if (!(g_hash_table_remove (comp->priv->objects_hash, element))) - goto chiringuito; + g_hash_table_remove (comp->priv->objects_hash, element); update_required = OBJECT_IN_ACTIVE_SEGMENT (comp, element) || (GNL_OBJECT_PRIORITY (element) == G_MAXUINT32) || @@ -2671,9 +2676,7 @@ beach: } gst_object_unref (element); - return ret; -chiringuito: - COMP_OBJECTS_UNLOCK (comp); - goto beach; +out: + return ret; } diff --git a/tests/check/gnl/gnlcomposition.c b/tests/check/gnl/gnlcomposition.c index dcb4f1a..9063a1c 100644 --- a/tests/check/gnl/gnlcomposition.c +++ b/tests/check/gnl/gnlcomposition.c @@ -214,6 +214,25 @@ GST_START_TEST (test_change_object_start_stop_in_current_stack) GST_END_TEST; +GST_START_TEST (test_remove_invalid_object) +{ + GstBin *composition; + GstElement *source1, *source2; + + composition = GST_BIN (gst_element_factory_make ("gnlcomposition", + "composition")); + source1 = gst_element_factory_make ("gnlsource", "source1"); + source2 = gst_element_factory_make ("gnlsource", "source2"); + + gst_bin_add (composition, source1); + fail_if (gst_bin_remove (composition, source2)); + fail_unless (gst_bin_remove (composition, source1)); + + gst_object_unref (composition); +} + +GST_END_TEST; + Suite * gnonlin_suite (void) { @@ -223,6 +242,7 @@ gnonlin_suite (void) suite_add_tcase (s, tc_chain); tcase_add_test (tc_chain, test_change_object_start_stop_in_current_stack); + tcase_add_test (tc_chain, test_remove_invalid_object); return s; } -- cgit v1.2.3