mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-06-06 07:28:53 +00:00
base-xml-formatter: properly handle GFile from wrong uri
Summary: g_file_new_for_uri never fails so GFile always has valid pointer. And fix a bug of double unref from D303. Reviewers: thiblahute Differential Revision: https://phabricator.freedesktop.org/D310
This commit is contained in:
parent
61da5ad63c
commit
2b4e89c75e
1 changed files with 20 additions and 15 deletions
|
@ -21,6 +21,10 @@
|
||||||
#include "ges.h"
|
#include "ges.h"
|
||||||
#include "ges-internal.h"
|
#include "ges-internal.h"
|
||||||
|
|
||||||
|
GST_DEBUG_CATEGORY_STATIC (base_xml_formatter);
|
||||||
|
#undef GST_CAT_DEFAULT
|
||||||
|
#define GST_CAT_DEFAULT base_xml_formatter
|
||||||
|
|
||||||
#define parent_class ges_base_xml_formatter_parent_class
|
#define parent_class ges_base_xml_formatter_parent_class
|
||||||
G_DEFINE_ABSTRACT_TYPE (GESBaseXmlFormatter, ges_base_xml_formatter,
|
G_DEFINE_ABSTRACT_TYPE (GESBaseXmlFormatter, ges_base_xml_formatter,
|
||||||
GES_TYPE_FORMATTER);
|
GES_TYPE_FORMATTER);
|
||||||
|
@ -167,10 +171,17 @@ create_parser_context (GESBaseXmlFormatter * self, const gchar * uri,
|
||||||
|
|
||||||
GError *err = NULL;
|
GError *err = NULL;
|
||||||
|
|
||||||
if ((file = g_file_new_for_uri (uri)) == NULL)
|
GST_DEBUG_OBJECT (self, "loading xml from %s", uri);
|
||||||
goto wrong_uri;
|
|
||||||
|
file = g_file_new_for_uri (uri);
|
||||||
|
|
||||||
/* TODO Handle GCancellable */
|
/* TODO Handle GCancellable */
|
||||||
|
if (!g_file_query_exists (file, NULL)) {
|
||||||
|
err = g_error_new (GST_RESOURCE_ERROR, GST_RESOURCE_ERROR_FAILED,
|
||||||
|
"Invalid URI: \"%s\"", uri);
|
||||||
|
goto failed;
|
||||||
|
}
|
||||||
|
|
||||||
if (!g_file_load_contents (file, NULL, &xmlcontent, &xmlsize, NULL, &err))
|
if (!g_file_load_contents (file, NULL, &xmlcontent, &xmlsize, NULL, &err))
|
||||||
goto failed;
|
goto failed;
|
||||||
|
|
||||||
|
@ -187,26 +198,17 @@ create_parser_context (GESBaseXmlFormatter * self, const gchar * uri,
|
||||||
if (!g_markup_parse_context_end_parse (parsecontext, &err))
|
if (!g_markup_parse_context_end_parse (parsecontext, &err))
|
||||||
goto failed;
|
goto failed;
|
||||||
|
|
||||||
done:
|
|
||||||
if (xmlcontent)
|
|
||||||
g_free (xmlcontent);
|
|
||||||
|
|
||||||
if (file)
|
done:
|
||||||
g_object_unref (file);
|
g_free (xmlcontent);
|
||||||
|
g_object_unref (file);
|
||||||
|
|
||||||
return parsecontext;
|
return parsecontext;
|
||||||
|
|
||||||
wrong_uri:
|
|
||||||
GST_WARNING ("%s wrong uri", uri);
|
|
||||||
|
|
||||||
goto done;
|
|
||||||
|
|
||||||
failed:
|
failed:
|
||||||
|
GST_WARNING ("failed to load contents from \"%s\"", uri);
|
||||||
g_propagate_error (error, err);
|
g_propagate_error (error, err);
|
||||||
|
|
||||||
if (file)
|
|
||||||
g_object_unref (file);
|
|
||||||
|
|
||||||
if (parsecontext) {
|
if (parsecontext) {
|
||||||
g_markup_parse_context_free (parsecontext);
|
g_markup_parse_context_free (parsecontext);
|
||||||
parsecontext = NULL;
|
parsecontext = NULL;
|
||||||
|
@ -410,6 +412,9 @@ ges_base_xml_formatter_class_init (GESBaseXmlFormatterClass * self_class)
|
||||||
formatter_klass->save_to_uri = _save_to_uri;
|
formatter_klass->save_to_uri = _save_to_uri;
|
||||||
|
|
||||||
self_class->save = NULL;
|
self_class->save = NULL;
|
||||||
|
|
||||||
|
GST_DEBUG_CATEGORY_INIT (base_xml_formatter, "base-xml-formatter",
|
||||||
|
GST_DEBUG_FG_BLUE | GST_DEBUG_BOLD, "Base XML Formatter");
|
||||||
}
|
}
|
||||||
|
|
||||||
/***********************************************
|
/***********************************************
|
||||||
|
|
Loading…
Reference in a new issue