From: Luca Boccassi Date: Fri, 14 Aug 2020 10:05:42 +0000 (+0100) Subject: shared/udev-util: fix sd_device leak in device_wait_for_initialization X-Git-Tag: v247-rc1~429^2 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F16705%2Fhead;p=thirdparty%2Fsystemd.git shared/udev-util: fix sd_device leak in device_wait_for_initialization If the caller doesn't pass a return pointer, or if sd_event_loop fails after the device was found and referenced, it never gets dereferenced. --- diff --git a/src/shared/udev-util.c b/src/shared/udev-util.c index eb79bbbcf06..8b27a6d0d03 100644 --- a/src/shared/udev-util.c +++ b/src/shared/udev-util.c @@ -138,6 +138,12 @@ struct DeviceMonitorData { sd_device *device; }; +static void device_monitor_data_free(struct DeviceMonitorData *d) { + assert(d); + + sd_device_unref(d->device); +} + static int device_monitor_handler(sd_device_monitor *monitor, sd_device *device, void *userdata) { struct DeviceMonitorData *data = userdata; const char *sysname; @@ -183,7 +189,7 @@ static int device_wait_for_initialization_internal( _cleanup_(sd_event_unrefp) sd_event *event = NULL; /* Ensure that if !_device && devlink, device gets unrefd on errors since it will be new */ _cleanup_(sd_device_unrefp) sd_device *device = sd_device_ref(_device); - struct DeviceMonitorData data = { + _cleanup_(device_monitor_data_free) struct DeviceMonitorData data = { .devlink = devlink, }; int r;