ratbagd: fix assertion error when quitting with more than 1 devices attached

RATBAGD_FOREACH_DEVICE does not allow unlinking the device during the loop.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
This commit is contained in:
Peter Hutterer
2017-08-28 14:07:54 +10:00
parent cfd93cf332
commit 643a4a89f4
2 changed files with 8 additions and 2 deletions

View File

@@ -486,12 +486,12 @@ static const struct ratbag_interface ratbagd_lib_interface = {
static struct ratbagd *ratbagd_free(struct ratbagd *ctx)
{
struct ratbagd_device *device;
struct ratbagd_device *device, *tmp;
if (!ctx)
return NULL;
RATBAGD_DEVICE_FOREACH(device, ctx)
RATBAGD_DEVICE_FOREACH_SAFE(device, tmp, ctx)
ratbagd_device_unlink(device);
ctx->bus = sd_bus_flush_close_unref(ctx->bus);

View File

@@ -169,6 +169,12 @@ struct ratbagd_device *ratbagd_device_next(struct ratbagd_device *device);
(_device); \
(_device) = ratbagd_device_next(_device))
#define RATBAGD_DEVICE_FOREACH_SAFE(_device, _safe, _ctx) \
for (_device = ratbagd_device_first(_ctx), \
_safe = (_device) ? ratbagd_device_next(_device) : NULL; \
(_device); \
_device = (_safe), \
_safe = (_safe) ? ratbagd_device_next(_safe) : NULL)
/*
* Context
*/