fbd-dev-leds: Use automatic deep cleanup for device list

The current logic was fragile and failed e.g. when the
FEEDBACKD_UDEV_VAL_LED would not match leaking the dev since the
g_object_unref() at the end of the loop was never hit.

Prevent that with automatic cleanup and explicitly ref'ing the
devs we want to use.
This commit is contained in:
Guido Günther
2021-04-26 09:34:23 +00:00
committed by Guido Gunther
parent 957fa1be83
commit 4c30fafc6e
+2 -6
View File
@@ -94,8 +94,7 @@ initable_init (GInitable *initable,
{
const gchar * const subsystems[] = { LED_SUBSYSTEM, NULL };
FbdDevLeds *self = FBD_DEV_LEDS (initable);
g_autoptr (GList) leds;
g_autolist (GUdevDevice) leds = NULL;
gboolean found = FALSE;
self->client = g_udev_client_new (subsystems);
@@ -132,7 +131,7 @@ initable_init (GInitable *initable,
continue;
led = g_malloc0 (sizeof(FbdDevLed));
led->dev = dev;
led->dev = g_object_ref (dev);
led->color = i;
led->max_brightness = brightness;
path = g_udev_device_get_sysfs_path (dev);
@@ -142,9 +141,6 @@ initable_init (GInitable *initable,
break;
}
}
if (!led)
g_object_unref (dev);
}
/* TODO: listen for new leds via udev events */