summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Bass <floobleflam@gmail.com>2017-04-20 10:24:30 +0100
committerSebastian Dröge <sebastian@centricular.com>2017-04-20 10:40:32 +0100
commit6eb36406f0c62d7f82436a3d9aa6c216ffaa62ab (patch)
treeb5faf495d458e7040ae63e76c5334bbaef15d4c9
parent9e3b63e1097e9f7219d2223e80b391f477210121 (diff)
downloadgstreamer-plugins-bad-6eb36406f0c62d7f82436a3d9aa6c216ffaa62ab.tar.gz
ttmlparse: Fix potential resource leak identified by coverity.
If multiple styles/regions with the same ID are present in the input (which is not allowed in TTML), use the last and give a warning. Fixes CID #1405134.
-rw-r--r--ext/ttml/ttmlparse.c21
1 files changed, 13 insertions, 8 deletions
diff --git a/ext/ttml/ttmlparse.c b/ext/ttml/ttmlparse.c
index cb54fc363..777f361c1 100644
--- a/ext/ttml/ttmlparse.c
+++ b/ext/ttml/ttmlparse.c
@@ -1306,8 +1306,9 @@ ttml_filter_content_nodes (GNode * node)
}
-/* Store child elements of @node with name @element_name in @table, as long as
- * @table doesn't already contain an element with the same ID. */
+/* Store in @table child elements of @node with name @element_name. A child
+ * element with the same ID as an existing entry in @table will overwrite the
+ * existing entry. */
static void
ttml_store_unique_children (xmlNodePtr node, const gchar * element_name,
GHashTable * table)
@@ -1317,11 +1318,15 @@ ttml_store_unique_children (xmlNodePtr node, const gchar * element_name,
for (ptr = node->children; ptr; ptr = ptr->next) {
if (xmlStrcmp (ptr->name, (const xmlChar *) element_name) == 0) {
TtmlElement *element = ttml_parse_element (ptr);
+ gboolean new_key;
- if (element)
- if (!g_hash_table_contains (table, element->id))
- g_hash_table_insert (table, (gpointer) (element->id),
- (gpointer) element);
+ if (element) {
+ new_key = g_hash_table_insert (table, g_strdup (element->id), element);
+ if (!new_key)
+ GST_CAT_WARNING (ttmlparse_debug,
+ "Document contains two %s elements with the same ID (\"%s\").",
+ element_name, element->id);
+ }
}
}
}
@@ -1762,9 +1767,9 @@ ttml_parse (const gchar * input, GstClockTime begin, GstClockTime duration)
}
GST_CAT_LOG (ttmlparse_debug, "Input:\n%s", input);
- styles_table = g_hash_table_new_full (g_str_hash, g_str_equal, NULL,
+ styles_table = g_hash_table_new_full (g_str_hash, g_str_equal, g_free,
(GDestroyNotify) ttml_delete_element);
- regions_table = g_hash_table_new_full (g_str_hash, g_str_equal, NULL,
+ regions_table = g_hash_table_new_full (g_str_hash, g_str_equal, g_free,
(GDestroyNotify) ttml_delete_element);
/* Parse input. */