From b53702ad0beff0cc85c17421df72ae1e7471c362 Mon Sep 17 00:00:00 2001 From: Aren Moynihan Date: Fri, 4 Oct 2024 11:21:25 -0400 Subject: [PATCH] manager: modem_reset: fix file descriptor leek fd wasn't being closed if the write failed. Theoretically if a system with an unstable modem ran for long enough, this could bring down eg25-manager. --- src/manager.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/manager.c b/src/manager.c index 38e71a6..7420c5f 100644 --- a/src/manager.c +++ b/src/manager.c @@ -226,24 +226,26 @@ gboolean modem_reset(struct EG25Manager *manager) g_warning("Unable to open /sys/bus/usb/drivers/usb/unbind"); goto error; } + ret = write(fd, manager->modem_usb_id, len); + close(fd); if (ret < len) { g_warning("Couldn't unbind modem: wrote %d/%d bytes", ret, len); goto error; } - close(fd); fd = open("/sys/bus/usb/drivers/usb/bind", O_WRONLY); if (fd < 0) { - g_warning("Unable to open /sys/bus/usb/drivers/usb/unbind"); + g_warning("Unable to open /sys/bus/usb/drivers/usb/bind"); goto error; } + ret = write(fd, manager->modem_usb_id, len); + close(fd); if (ret < len) { g_warning("Couldn't bind modem: wrote %d/%d bytes", ret, len); goto error; } - close(fd); g_message("Successfully reset modem's USB connection");