meta: Warn if a meta implementation is registered without init function

This previously caused uninitialized memory unless something else was
initializing all the fields explicitly to something.

To be on the safe side, we also allocate metas without init function to all
zeroes now as it was relatively common.

https://bugzilla.gnome.org/show_bug.cgi?id=764902
This commit is contained in:
Sebastian Dröge 2016-04-13 10:21:15 +03:00
parent 00e4499b15
commit 3f3af84a8f
2 changed files with 12 additions and 1 deletions

View file

@ -2091,7 +2091,14 @@ gst_buffer_add_meta (GstBuffer * buffer, const GstMetaInfo * info,
/* create a new slice */
size = ITEM_SIZE (info);
item = g_slice_alloc (size);
/* We warn in gst_meta_register() about metas without
* init function but let's play safe here and prevent
* uninitialized memory
*/
if (!info->init_func)
item = g_slice_alloc0 (size);
else
item = g_slice_alloc (size);
result = &item->meta;
result->info = info;
result->flags = GST_META_FLAG_NONE;

View file

@ -172,6 +172,10 @@ gst_meta_register (GType api, const gchar * impl, gsize size,
g_return_val_if_fail (impl != NULL, NULL);
g_return_val_if_fail (size != 0, NULL);
if (init_func == NULL)
g_critical ("Registering meta implementation '%s' without init function",
impl);
/* first try to register the implementation name. It's possible
* that this fails because it was already registered. Don't warn,
* glib did this for us already. */