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.
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user