fix(sni): correct watcher host teardown signaling

Return the host registration method correctly on duplicate host registration
and emit HostUnregistered instead of HostRegistered when the last host
vanishes.

Also free the corresponding name watch once the tracked host/item disappears so
the watcher does not leak stale watch records.

Signed-off-by: Austin Horstman <khaneliman12@gmail.com>
This commit is contained in:
Austin Horstman
2026-03-08 01:08:43 -06:00
parent 2a748f1a56
commit 78f6cde232

View File

@@ -69,7 +69,7 @@ gboolean Watcher::handleRegisterHost(Watcher* obj, GDBusMethodInvocation* invoca
if (watch != nullptr) { if (watch != nullptr) {
g_warning("Status Notifier Host with bus name '%s' and object path '%s' is already registered", g_warning("Status Notifier Host with bus name '%s' and object path '%s' is already registered",
bus_name, object_path); bus_name, object_path);
sn_watcher_complete_register_item(obj->watcher_, invocation); sn_watcher_complete_register_host(obj->watcher_, invocation);
return TRUE; return TRUE;
} }
watch = gfWatchNew(GF_WATCH_TYPE_HOST, service, bus_name, object_path, obj); watch = gfWatchNew(GF_WATCH_TYPE_HOST, service, bus_name, object_path, obj);
@@ -158,7 +158,7 @@ void Watcher::nameVanished(GDBusConnection* connection, const char* name, gpoint
watch->watcher->hosts_ = g_slist_remove(watch->watcher->hosts_, watch); watch->watcher->hosts_ = g_slist_remove(watch->watcher->hosts_, watch);
if (watch->watcher->hosts_ == nullptr) { if (watch->watcher->hosts_ == nullptr) {
sn_watcher_set_is_host_registered(watch->watcher->watcher_, FALSE); sn_watcher_set_is_host_registered(watch->watcher->watcher_, FALSE);
sn_watcher_emit_host_registered(watch->watcher->watcher_); sn_watcher_emit_host_unregistered(watch->watcher->watcher_);
} }
} else if (watch->type == GF_WATCH_TYPE_ITEM) { } else if (watch->type == GF_WATCH_TYPE_ITEM) {
watch->watcher->items_ = g_slist_remove(watch->watcher->items_, watch); watch->watcher->items_ = g_slist_remove(watch->watcher->items_, watch);
@@ -167,6 +167,7 @@ void Watcher::nameVanished(GDBusConnection* connection, const char* name, gpoint
sn_watcher_emit_item_unregistered(watch->watcher->watcher_, tmp); sn_watcher_emit_item_unregistered(watch->watcher->watcher_, tmp);
g_free(tmp); g_free(tmp);
} }
gfWatchFree(watch);
} }
void Watcher::updateRegisteredItems(SnWatcher* obj) { void Watcher::updateRegisteredItems(SnWatcher* obj) {