From 94200b03fe483f9d0df87483fa2f30301e2b9f31 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Wed, 20 Jun 2018 16:32:32 +0200 Subject: [PATCH] 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. --- src/devices/nm-device-factory.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/devices/nm-device-factory.c b/src/devices/nm-device-factory.c index eef3a6c954..bc717bb3d6 100644 --- a/src/devices/nm-device-factory.c +++ b/src/devices/nm-device-factory.c @@ -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++) {