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 }; const gchar * const subsystems[] = { LED_SUBSYSTEM, NULL };
FbdDevLeds *self = FBD_DEV_LEDS (initable); FbdDevLeds *self = FBD_DEV_LEDS (initable);
g_autolist (GUdevDevice) leds = NULL;
g_autoptr (GList) leds;
gboolean found = FALSE; gboolean found = FALSE;
self->client = g_udev_client_new (subsystems); self->client = g_udev_client_new (subsystems);
@@ -132,7 +131,7 @@ initable_init (GInitable *initable,
continue; continue;
led = g_malloc0 (sizeof(FbdDevLed)); led = g_malloc0 (sizeof(FbdDevLed));
led->dev = dev; led->dev = g_object_ref (dev);
led->color = i; led->color = i;
led->max_brightness = brightness; led->max_brightness = brightness;
path = g_udev_device_get_sysfs_path (dev); path = g_udev_device_get_sysfs_path (dev);
@@ -142,9 +141,6 @@ initable_init (GInitable *initable,
break; break;
} }
} }
if (!led)
g_object_unref (dev);
} }
/* TODO: listen for new leds via udev events */ /* TODO: listen for new leds via udev events */