From 4764a62afc34d6662f77fcf122cc0b256e17d223 Mon Sep 17 00:00:00 2001 From: Alex Date: Sun, 5 Jul 2026 10:07:10 +0200 Subject: [PATCH] fix(wwan): null members after unref and guard destructor to avoid double-free The destructor unconditionally unref'd current_modem, manager and connection, but the constructor can leave them NULL or already-unref'd: - On the mm_manager_new_sync failure path the ctor unref'd connection without nulling it, so the dtor unref'd it a second time -> double-free. - On the g_bus_get_sync failure path all three stay NULL, and in the common no-WWAN-hardware case current_modem is NULL, so the dtor ran g_object_unref(NULL) -> G_IS_OBJECT assertion criticals. Use g_clear_object() in the failing ctor path (unref + null) and in the destructor (NULL-safe unref + null). Teardown is now safe for every ctor outcome (bus fail, MM fail, no modem, normal), and a normal run still unrefs each owned ref exactly once. --- src/modules/wwan.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/modules/wwan.cpp b/src/modules/wwan.cpp index 86e68624..c741405d 100644 --- a/src/modules/wwan.cpp +++ b/src/modules/wwan.cpp @@ -43,7 +43,7 @@ waybar::modules::Wwan::Wwan(const std::string& id, const Json::Value& config) if (error) { spdlog::error("Failed to create ModemManager proxy: " + std::string(error->message)); g_error_free(error); - g_object_unref(connection); + g_clear_object(&connection); return; } @@ -302,7 +302,7 @@ auto waybar::modules::Wwan::update() -> void { } waybar::modules::Wwan::~Wwan() { - g_object_unref(current_modem); - g_object_unref(manager); - g_object_unref(connection); + g_clear_object(¤t_modem); + g_clear_object(&manager); + g_clear_object(&connection); }