diff --git a/src/at.c b/src/at.c index 39cb912..87c7030 100644 --- a/src/at.c +++ b/src/at.c @@ -206,7 +206,8 @@ int at_init(struct EG25Manager *manager) void at_destroy(struct EG25Manager *manager) { g_source_remove(manager->at_source); - close(manager->at_fd); + if (manager->at_fd > 0) + close(manager->at_fd); } void at_sequence_configure(struct EG25Manager *manager) diff --git a/src/gpio.c b/src/gpio.c index 95973e5..fac7358 100644 --- a/src/gpio.c +++ b/src/gpio.c @@ -189,10 +189,18 @@ void gpio_destroy(struct EG25Manager *manager) { int i; - for (i = 0; i < GPIO_OUT_COUNT; i++) - gpiod_line_release(manager->gpio_out[i]); + for (i = 0; i < GPIO_OUT_COUNT; i++) { + if (manager->gpio_out[i]) + gpiod_line_release(manager->gpio_out[i]); + } - gpiod_chip_close(manager->gpiochip[0]); + for (i = 0; i < GPIO_IN_COUNT; i++) { + if (manager->gpio_in[i]) + gpiod_line_release(manager->gpio_in[i]); + } + + if (manager->gpiochip[0]) + gpiod_chip_close(manager->gpiochip[0]); if (manager->gpiochip[1]) gpiod_chip_close(manager->gpiochip[1]); } diff --git a/src/mm-iface.c b/src/mm-iface.c index 3017a71..f1021de 100644 --- a/src/mm-iface.c +++ b/src/mm-iface.c @@ -47,6 +47,9 @@ static void add_modem(struct EG25Manager *manager, GDBusObject *object) modem_configure(manager); path = mm_modem_get_device(manager->mm_modem); + + if (manager->modem_usb_id) + g_free(manager->modem_usb_id); manager->modem_usb_id = g_strdup(strrchr(path, '/') + 1); gdbus_modem = MM_GDBUS_MODEM(manager->mm_modem); @@ -189,5 +192,12 @@ void mm_iface_init(struct EG25Manager *manager) void mm_iface_destroy(struct EG25Manager *manager) { - g_clear_object(&manager->mm_manager); + if (manager->mm_manager) { + g_clear_object(&manager->mm_manager); + manager->mm_manager = NULL; + } + if (manager->mm_watch != 0) { + g_bus_unwatch_name(manager->mm_watch); + manager->mm_watch = 0; + } } diff --git a/src/suspend.c b/src/suspend.c index 9ed920b..8296696 100644 --- a/src/suspend.c +++ b/src/suspend.c @@ -114,11 +114,12 @@ static void name_owner_cb(GObject *object, g_assert(proxy == manager->suspend_proxy); owner = g_dbus_proxy_get_name_owner(proxy); - if (owner) + if (owner) { take_inhibitor(manager); - else + g_free(owner); + } else { drop_inhibitor(manager); - g_free(owner); + } } static void on_proxy_acquired(GObject *object, @@ -139,9 +140,10 @@ static void on_proxy_acquired(GObject *object, g_signal_connect(manager->suspend_proxy, "g-signal", G_CALLBACK(signal_cb), manager); owner = g_dbus_proxy_get_name_owner(manager->suspend_proxy); - if (owner) + if (owner) { take_inhibitor(manager); - g_free(owner); + g_free(owner); + } } void suspend_init(struct EG25Manager *manager) @@ -156,7 +158,10 @@ void suspend_init(struct EG25Manager *manager) void suspend_destroy(struct EG25Manager *manager) { drop_inhibitor(manager); - g_object_unref(manager->suspend_proxy); + if (manager->suspend_proxy) { + g_object_unref(manager->suspend_proxy); + manager->suspend_proxy = NULL; + } } void suspend_inhibit(struct EG25Manager *manager, gboolean inhibit)