summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim-Philipp Müller <tim.muller@collabora.co.uk>2011-01-03 01:06:06 +0000
committerTim-Philipp Müller <tim.muller@collabora.co.uk>2011-01-03 15:57:20 +0000
commitee5b369ffd72368e53b5fdfce46390efbc83481d (patch)
treeaedc0f750107e654ea713b5b51410365ebc5cec3
parent373be6f14ea8f548360dc565c6124c5368cc273c (diff)
gstvalue: make new gst_value_list_merge() work properly
Fix freeing of partially-inited list value when both values passed are equal and we want to return a single non-list value as result. Fixes unit test. Also fix up docs a bit. https://bugzilla.gnome.org/show_bug.cgi?id=637776
-rw-r--r--gst/gstvalue.c25
1 files changed, 18 insertions, 7 deletions
diff --git a/gst/gstvalue.c b/gst/gstvalue.c
index 84a4405595..072a8cb35c 100644
--- a/gst/gstvalue.c
+++ b/gst/gstvalue.c
@@ -390,11 +390,14 @@ gst_value_list_concat (GValue * dest, const GValue * value1,
* @value1: a #GValue
* @value2: a #GValue
*
- * Merges copies of @value1 and @value2 into a list. Values that are not
+ * Merges copies of @value1 and @value2. Values that are not
* of type #GST_TYPE_LIST are treated as if they were lists of length 1.
- * @dest will be initialized to the type #GST_TYPE_LIST.
*
- * The resulting list won't have duplicated values.
+ * The result will be put into @dest and will either be a list that will not
+ * contain any duplicates, or a non-list type (if @value1 and @value2
+ * were equal).
+ *
+ * Since: 0.10.32
*/
void
gst_value_list_merge (GValue * dest, const GValue * value1,
@@ -467,11 +470,19 @@ gst_value_list_merge (GValue * dest, const GValue * value1,
/* shrink list */
g_array_set_size (array, new_size);
} else {
- GValue *tmp = dest;
+ GValue single_dest;
+
+ /* size is 1, take single value in list and make it new dest */
+ single_dest = g_array_index (array, GValue, 0);
+
+ /* clean up old value allocations: must set array size to 0, because
+ * allocated values are not inited meaning g_value_unset() will not
+ * work on them */
+ g_array_set_size (array, 0);
+ g_value_unset (dest);
- /* turn into single value */
- gst_value_init_and_copy (dest, &g_array_index (array, GValue, 0));
- g_value_unset (tmp);
+ /* the single value is our new result */
+ *dest = single_dest;
}
}
}