summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStefan Kost <ensonic@users.sf.net>2011-08-08 19:36:04 +0200
committerStefan Kost <ensonic@users.sf.net>2011-08-10 13:45:49 +0200
commit20618b4c28accf4306de5766fd1628d8709b7af0 (patch)
treeb9bb6c6bd81c6415f43b3681d3b45dc0aa36b216
parente77098101fc51a7f42d7f5eaee0ff1350744cb56 (diff)
registry: move utf-8 validation to registry saving time
Instead of checking for valid utf-8 element-details every time we create elements (from plugin-init or registry), do it before we save the registry. Fixes #656193.
-rw-r--r--gst/gstelementdetails.h34
-rw-r--r--gst/gstregistrychunks.c26
2 files changed, 33 insertions, 27 deletions
diff --git a/gst/gstelementdetails.h b/gst/gstelementdetails.h
index b59878a89..fe946bac2 100644
--- a/gst/gstelementdetails.h
+++ b/gst/gstelementdetails.h
@@ -35,33 +35,21 @@ __gst_element_details_clear (GstElementDetails * dp)
memset (dp, 0, sizeof (GstElementDetails));
}
-#define VALIDATE_SET(__dest, __src, __entry) \
-G_STMT_START { \
- if (g_utf8_validate (__src->__entry, -1, NULL)) { \
- __dest->__entry = g_strdup (__src->__entry); \
- } else { \
- g_warning ("Invalid UTF-8 in " G_STRINGIFY (__entry) ": %s", \
- __src->__entry); \
- __dest->__entry = g_strdup ("[ERROR: invalid UTF-8]"); \
- } \
-} G_STMT_END
-
-static inline void
-__gst_element_details_set (GstElementDetails * dest,
- const GstElementDetails * src)
-{
- VALIDATE_SET (dest, src, longname);
- VALIDATE_SET (dest, src, klass);
- VALIDATE_SET (dest, src, description);
- VALIDATE_SET (dest, src, author);
-}
-
static inline void
__gst_element_details_copy (GstElementDetails * dest,
const GstElementDetails * src)
{
- __gst_element_details_clear (dest);
- __gst_element_details_set (dest, src);
+ g_free (dest->longname);
+ dest->longname = g_strdup (src->longname);
+
+ g_free (dest->klass);
+ dest->klass = g_strdup (src->klass);
+
+ g_free (dest->description);
+ dest->description = g_strdup (src->description);
+
+ g_free (dest->author);
+ dest->author = g_strdup (src->author);
}
G_END_DECLS
diff --git a/gst/gstregistrychunks.c b/gst/gstregistrychunks.c
index 684a18153..4556eb42e 100644
--- a/gst/gstregistrychunks.c
+++ b/gst/gstregistrychunks.c
@@ -207,6 +207,16 @@ gst_registry_chunks_save_pad_template (GList ** list,
return TRUE;
}
+#define VALIDATE_UTF8(__details, __entry) \
+G_STMT_START { \
+ if (!g_utf8_validate (__details->__entry, -1, NULL)) { \
+ g_warning ("Invalid UTF-8 in " G_STRINGIFY (__entry) ": %s", \
+ __details->__entry); \
+ g_free (__details->__entry); \
+ __details->__entry = g_strdup ("[ERROR: invalid UTF-8]"); \
+ } \
+} G_STMT_END
+
/*
* gst_registry_chunks_save_feature:
*
@@ -230,6 +240,14 @@ gst_registry_chunks_save_feature (GList ** list, GstPluginFeature * feature)
if (GST_IS_ELEMENT_FACTORY (feature)) {
GstRegistryChunkElementFactory *ef;
GstElementFactory *factory = GST_ELEMENT_FACTORY (feature);
+ GstElementDetails *details = &factory->details;
+
+ /* do the utf-8 validation of the element factory details here to avoid
+ * doing it every time we load */
+ VALIDATE_UTF8 (details, longname);
+ VALIDATE_UTF8 (details, klass);
+ VALIDATE_UTF8 (details, description);
+ VALIDATE_UTF8 (details, author);
/* Initialize with zeroes because of struct padding and
* valgrind complaining about copying unitialized memory
@@ -285,10 +303,10 @@ gst_registry_chunks_save_feature (GList ** list, GstPluginFeature * feature)
}
/* pack element factory strings */
- gst_registry_chunks_save_const_string (list, factory->details.author);
- gst_registry_chunks_save_const_string (list, factory->details.description);
- gst_registry_chunks_save_const_string (list, factory->details.klass);
- gst_registry_chunks_save_const_string (list, factory->details.longname);
+ gst_registry_chunks_save_const_string (list, details->author);
+ gst_registry_chunks_save_const_string (list, details->description);
+ gst_registry_chunks_save_const_string (list, details->klass);
+ gst_registry_chunks_save_const_string (list, details->longname);
if (factory->meta_data) {
gst_registry_chunks_save_string (list,
gst_structure_to_string (factory->meta_data));