encoding-profile: Don't use preset_name string after free

When we run the loop for another time and do not have a preset name, we would
try to print the preset name of a previous iteration that is already freed.

Also move some other variables into the block where they are actually used
to prevent similar mistakes in the future.

CID 1346536
This commit is contained in:
Sebastian Dröge 2015-12-29 17:54:44 +02:00
parent 898940a37f
commit f31240a765

View file

@ -1342,17 +1342,12 @@ combo_search (const gchar * pname)
static GstEncodingProfile * static GstEncodingProfile *
parse_encoding_profile (const gchar * value) parse_encoding_profile (const gchar * value)
{ {
GstCaps *caps;
GstEncodingProfile *res; GstEncodingProfile *res;
char *preset_name = NULL;
gchar **restriction_format, **preset_v;
guint i, presence = 0;
GstCaps *restrictioncaps = NULL;
gchar **strpresence_v, **strcaps_v = g_strsplit (value, ":", 0); gchar **strpresence_v, **strcaps_v = g_strsplit (value, ":", 0);
guint i;
if (strcaps_v[0] && *strcaps_v[0]) { if (strcaps_v[0] && *strcaps_v[0]) {
caps = gst_caps_from_string (strcaps_v[0]); GstCaps *caps = gst_caps_from_string (strcaps_v[0]);
if (caps == NULL) { if (caps == NULL) {
GST_ERROR ("Could not parse caps %s", strcaps_v[0]); GST_ERROR ("Could not parse caps %s", strcaps_v[0]);
return NULL; return NULL;
@ -1368,6 +1363,11 @@ parse_encoding_profile (const gchar * value)
for (i = 1; strcaps_v[i] && *strcaps_v[i]; i++) { for (i = 1; strcaps_v[i] && *strcaps_v[i]; i++) {
GstEncodingProfile *profile = NULL; GstEncodingProfile *profile = NULL;
gchar *strcaps, *strpresence; gchar *strcaps, *strpresence;
gchar *preset_name = NULL;
GstCaps *caps;
gchar **restriction_format, **preset_v;
guint presence = 0;
GstCaps *restrictioncaps = NULL;
restriction_format = g_strsplit (strcaps_v[i], "->", 0); restriction_format = g_strsplit (strcaps_v[i], "->", 0);
if (restriction_format[1]) { if (restriction_format[1]) {
@ -1449,8 +1449,7 @@ parse_encoding_profile (const gchar * value)
if (res) { if (res) {
if (gst_encoding_container_profile_add_profile if (gst_encoding_container_profile_add_profile
(GST_ENCODING_CONTAINER_PROFILE (res), (GST_ENCODING_CONTAINER_PROFILE (res), profile) == FALSE) {
profile) == FALSE) {
g_warning ("Can not create a preset for caps: %s", strcaps_v[i]); g_warning ("Can not create a preset for caps: %s", strcaps_v[i]);
return NULL; return NULL;