resolved: avoid dangling hashmap entry on RegisterService failure
bus_method_register_service() inserted the DnssdRegisteredService into m->dnssd_registered_services before assigning service->manager and before the sd_bus_track_new()/sd_bus_track_add_sender() calls, so if either failed, the destructor ran with service->manager still NULL, so its guarded hashmap_remove() was skipped and the freed service was left in the hashmap.
This commit is contained in:
@@ -2055,10 +2055,6 @@ static int bus_method_register_service(sd_bus_message *message, void *userdata,
|
||||
if (r == 0)
|
||||
return 1; /* Polkit will call us back */
|
||||
|
||||
r = hashmap_ensure_put(&m->dnssd_registered_services, &string_hash_ops, service->id, service);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
r = sd_bus_track_new(sd_bus_message_get_bus(message), &bus_track, dnssd_registered_service_on_bus_track, service);
|
||||
if (r < 0)
|
||||
return r;
|
||||
@@ -2069,6 +2065,10 @@ static int bus_method_register_service(sd_bus_message *message, void *userdata,
|
||||
|
||||
service->manager = m;
|
||||
|
||||
r = hashmap_ensure_put(&m->dnssd_registered_services, &string_hash_ops, service->id, service);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
service = NULL;
|
||||
|
||||
manager_refresh_rrs(m);
|
||||
|
||||
Reference in New Issue
Block a user