device: require that device-factories support at least one link-type or setting-type

If a device-factory wouldn't support any link-type or setting-type,
we would not take an additional reference to the @factory instance
(because, the factory is not added to one of the static hash tables).

As such, we would invoke the callback with a factory instance, which
is about to be destroyed immediately afterwards. That would be unusual
for device-plugins, because usually a device-plugin is never destroyed
and essentially leaked at exit.

Just don't get into that situation. All device plugins are internal API,
and they are known to support at least something. Assert for that.
This commit is contained in:
Thomas Haller 2018-06-20 16:32:32 +02:00
parent 4c43d7cad3
commit 94200b03fe

View file

@ -301,6 +301,10 @@ _add_factory (NMDeviceFactory *factory,
nm_device_factory_get_supported_types (factory, &link_types, &setting_types);
g_return_val_if_fail ( (link_types && link_types[0] > NM_LINK_TYPE_UNKNOWN)
|| (setting_types && setting_types[0]),
FALSE);
for (i = 0; link_types && link_types[i] > NM_LINK_TYPE_UNKNOWN; i++)
g_hash_table_insert (factories_by_link, GUINT_TO_POINTER (link_types[i]), g_object_ref (factory));
for (i = 0; setting_types && setting_types[i]; i++) {