Commit 1e1e9f21 authored by Edward Hervey's avatar Edward Hervey 🤘 Committed by Edward Hervey
Browse files

validate-utils: Only modify structure fields that really need updates

This avoids memory corruption in users of that structure which
were (rightfullly) assuming static fields (such as name) wouldn't
change. Without this, they would be using strings which will have been freed in
the meantime.

Part-of: <gstreamer/gst-devtools!252>
parent cdfa0778
......@@ -1339,8 +1339,6 @@ done:
static gboolean
_structure_set_variables (GQuark field_id, GValue * value, ReplaceData * data)
{
gchar *str;
if (field_id == filename_quark || field_id == debug_quark
|| field_id == debug_quark)
return TRUE;
......@@ -1358,12 +1356,18 @@ _structure_set_variables (GQuark field_id, GValue * value, ReplaceData * data)
if (!G_VALUE_HOLDS_STRING (value))
return TRUE;
str =
gst_validate_replace_variables_in_string (data->source, data->local_vars,
g_value_get_string (value), data->flags);
if (str) {
g_value_set_string (value, str);
g_free (str);
if (!_variables_regex)
_variables_regex = g_regex_new ("\\$\\((\\w+)\\)", 0, 0, NULL);
/* Don't replace string contents unless really needed */
if (g_regex_match (_variables_regex, g_value_get_string (value), 0, NULL)) {
gchar *str = gst_validate_replace_variables_in_string (data->source,
data->local_vars,
g_value_get_string (value), data->flags);
if (str) {
g_value_set_string (value, str);
g_free (str);
}
}
if (!(data->flags & GST_VALIDATE_STRUCTURE_RESOLVE_VARIABLES_NO_EXPRESSION))
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment