summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThibault Saunier <tsaunier@gnome.org>2015-10-07 09:57:33 +0200
committerThibault Saunier <tsaunier@gnome.org>2015-10-07 09:57:33 +0200
commitcb84297f414f9003e85c7f0f3fc5384764778acb (patch)
tree2d61c133d1123d5899da71d67d28439d253dac0a
parent97815f3e8dc0166e4b00cf200bd1c79237ef5f4d (diff)
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
-rw-r--r--ges/ges-base-xml-formatter.c35
1 files changed, 20 insertions, 15 deletions
diff --git a/ges/ges-base-xml-formatter.c b/ges/ges-base-xml-formatter.c
index b639c5d8..5223ecb6 100644
--- a/ges/ges-base-xml-formatter.c
+++ b/ges/ges-base-xml-formatter.c
@@ -21,6 +21,10 @@
#include "ges.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
G_DEFINE_ABSTRACT_TYPE (GESBaseXmlFormatter, ges_base_xml_formatter,
GES_TYPE_FORMATTER);
@@ -167,10 +171,17 @@ create_parser_context (GESBaseXmlFormatter * self, const gchar * uri,
GError *err = NULL;
- if ((file = g_file_new_for_uri (uri)) == NULL)
- goto wrong_uri;
+ GST_DEBUG_OBJECT (self, "loading xml from %s", uri);
+
+ file = g_file_new_for_uri (uri);
/* 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))
goto failed;
@@ -187,26 +198,17 @@ create_parser_context (GESBaseXmlFormatter * self, const gchar * uri,
if (!g_markup_parse_context_end_parse (parsecontext, &err))
goto failed;
-done:
- if (xmlcontent)
- g_free (xmlcontent);
- if (file)
- g_object_unref (file);
+done:
+ g_free (xmlcontent);
+ g_object_unref (file);
return parsecontext;
-wrong_uri:
- GST_WARNING ("%s wrong uri", uri);
-
- goto done;
-
failed:
+ GST_WARNING ("failed to load contents from \"%s\"", uri);
g_propagate_error (error, err);
- if (file)
- g_object_unref (file);
-
if (parsecontext) {
g_markup_parse_context_free (parsecontext);
parsecontext = NULL;
@@ -410,6 +412,9 @@ ges_base_xml_formatter_class_init (GESBaseXmlFormatterClass * self_class)
formatter_klass->save_to_uri = _save_to_uri;
self_class->save = NULL;
+
+ GST_DEBUG_CATEGORY_INIT (base_xml_formatter, "base-xml-formatter",
+ GST_DEBUG_FG_BLUE | GST_DEBUG_BOLD, "Base XML Formatter");
}
/***********************************************