Merge pull request #18286 from ssahani/net-1
tree-wide: more use of hashmap_ensure_put() and TAKE_PTR()
This commit is contained in:
@@ -1983,11 +1983,7 @@ int bus_exec_context_set_transient_property(
|
||||
sc->data = TAKE_PTR(copy);
|
||||
sc->size = sz;
|
||||
|
||||
r = hashmap_ensure_allocated(&c->set_credentials, &exec_set_credential_hash_ops);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
r = hashmap_put(c->set_credentials, sc->id, sc);
|
||||
r = hashmap_ensure_put(&c->set_credentials, &exec_set_credential_hash_ops, sc->id, sc);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
|
||||
+1
-5
@@ -263,11 +263,7 @@ int job_install_deserialized(Job *j) {
|
||||
return log_unit_debug_errno(j->unit, SYNTHETIC_ERRNO(EEXIST),
|
||||
"Unit already has a job installed. Not installing deserialized job.");
|
||||
|
||||
r = hashmap_ensure_allocated(&j->manager->jobs, NULL);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
r = hashmap_put(j->manager->jobs, UINT32_TO_PTR(j->id), j);
|
||||
r = hashmap_ensure_put(&j->manager->jobs, NULL, UINT32_TO_PTR(j->id), j);
|
||||
if (r == -EEXIST)
|
||||
return log_unit_debug_errno(j->unit, r, "Job ID %" PRIu32 " already used, cannot deserialize job.", j->id);
|
||||
if (r < 0)
|
||||
|
||||
@@ -4536,14 +4536,12 @@ int config_parse_set_credential(
|
||||
sc->data = TAKE_PTR(unescaped);
|
||||
sc->size = l;
|
||||
|
||||
r = hashmap_ensure_allocated(&context->set_credentials, &exec_set_credential_hash_ops);
|
||||
r = hashmap_ensure_put(&context->set_credentials, &exec_set_credential_hash_ops, sc->id, sc);
|
||||
if (r == -ENOMEM)
|
||||
return log_oom();
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
r = hashmap_put(context->set_credentials, sc->id, sc);
|
||||
if (r < 0)
|
||||
return log_oom();
|
||||
|
||||
TAKE_PTR(sc);
|
||||
}
|
||||
|
||||
|
||||
@@ -483,13 +483,11 @@ static int setup_microhttpd_server(RemoteServer *s,
|
||||
goto error;
|
||||
}
|
||||
|
||||
r = hashmap_ensure_allocated(&s->daemons, &uint64_hash_ops);
|
||||
if (r < 0) {
|
||||
r = hashmap_ensure_put(&s->daemons, &uint64_hash_ops, &d->fd, d);
|
||||
if (r == -ENOMEM) {
|
||||
log_oom();
|
||||
goto error;
|
||||
}
|
||||
|
||||
r = hashmap_put(s->daemons, &d->fd, d);
|
||||
if (r < 0) {
|
||||
log_error_errno(r, "Failed to add daemon to hashmap: %m");
|
||||
goto error;
|
||||
|
||||
@@ -1943,11 +1943,7 @@ 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_allocated(&m->dnssd_services, &string_hash_ops);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
r = hashmap_put(m->dnssd_services, service->name, service);
|
||||
r = hashmap_ensure_put(&m->dnssd_services, &string_hash_ops, service->name, service);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
|
||||
@@ -557,15 +557,11 @@ int dns_packet_append_name(
|
||||
goto fail;
|
||||
}
|
||||
|
||||
r = hashmap_ensure_allocated(&p->names, &dns_name_hash_ops);
|
||||
r = hashmap_ensure_put(&p->names, &dns_name_hash_ops, s, SIZE_TO_PTR(n));
|
||||
if (r < 0)
|
||||
goto fail;
|
||||
|
||||
r = hashmap_put(p->names, s, SIZE_TO_PTR(n));
|
||||
if (r < 0)
|
||||
goto fail;
|
||||
|
||||
s = NULL;
|
||||
TAKE_PTR(s);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -117,14 +117,10 @@ static int dnssd_service_load(Manager *manager, const char *filename) {
|
||||
return r;
|
||||
|
||||
LIST_PREPEND(items, service->txt_data_items, txt_data);
|
||||
txt_data = NULL;
|
||||
TAKE_PTR(txt_data);
|
||||
}
|
||||
|
||||
r = hashmap_ensure_allocated(&manager->dnssd_services, &string_hash_ops);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
r = hashmap_put(manager->dnssd_services, service->name, service);
|
||||
r = hashmap_ensure_put(&manager->dnssd_services, &string_hash_ops, service->name, service);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
@@ -134,7 +130,7 @@ static int dnssd_service_load(Manager *manager, const char *filename) {
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
service = NULL;
|
||||
TAKE_PTR(service);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
+2
-10
@@ -336,11 +336,7 @@ static int rule_resolve_user(UdevRules *rules, const char *name, uid_t *ret) {
|
||||
if (!n)
|
||||
return -ENOMEM;
|
||||
|
||||
r = hashmap_ensure_allocated(&rules->known_users, &string_hash_ops);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
r = hashmap_put(rules->known_users, n, UID_TO_PTR(uid));
|
||||
r = hashmap_ensure_put(&rules->known_users, &string_hash_ops, n, UID_TO_PTR(uid));
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
@@ -375,11 +371,7 @@ static int rule_resolve_group(UdevRules *rules, const char *name, gid_t *ret) {
|
||||
if (!n)
|
||||
return -ENOMEM;
|
||||
|
||||
r = hashmap_ensure_allocated(&rules->known_groups, &string_hash_ops);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
r = hashmap_put(rules->known_groups, n, GID_TO_PTR(gid));
|
||||
r = hashmap_ensure_put(&rules->known_groups, &string_hash_ops, n, GID_TO_PTR(gid));
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
|
||||
@@ -157,15 +157,12 @@ static int parse_argv(int argc, char *argv[]) {
|
||||
if (!subsystem)
|
||||
return -ENOMEM;
|
||||
|
||||
r = hashmap_ensure_allocated(&arg_subsystem_filter, NULL);
|
||||
r = hashmap_ensure_put(&arg_subsystem_filter, NULL, subsystem, devtype);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
r = hashmap_put(arg_subsystem_filter, subsystem, devtype);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
subsystem = devtype = NULL;
|
||||
TAKE_PTR(subsystem);
|
||||
TAKE_PTR(devtype);
|
||||
break;
|
||||
}
|
||||
case 't':
|
||||
|
||||
Reference in New Issue
Block a user