udev: use hash ops with destructor

This commit is contained in:
Yu Watanabe
2025-01-23 18:19:28 +09:00
parent 57f15d05bf
commit a22620e39f
4 changed files with 12 additions and 12 deletions
+1 -1
View File
@@ -407,7 +407,7 @@ static int manager_set_environment_one(Manager *manager, const char *s) {
_cleanup_free_ char *old_key = NULL, *old_value = NULL;
old_value = hashmap_get2(manager->properties, key, (void**) &old_key);
r = hashmap_ensure_replace(&manager->properties, &string_hash_ops, key, value);
r = hashmap_ensure_replace(&manager->properties, &string_hash_ops_free_free, key, value);
if (r < 0) {
assert(!old_key);
assert(!old_value);
+2 -2
View File
@@ -52,8 +52,8 @@ static UdevEvent* udev_event_free(UdevEvent *event) {
sd_device_unref(event->dev);
sd_device_unref(event->dev_db_clone);
sd_netlink_unref(event->rtnl);
ordered_hashmap_free_free_key(event->run_list);
ordered_hashmap_free_free_free(event->seclabel_list);
ordered_hashmap_free(event->run_list);
ordered_hashmap_free(event->seclabel_list);
hashmap_free(event->written_sysattrs);
hashmap_free(event->written_sysctls);
free(event->program_result);
+1 -1
View File
@@ -139,7 +139,7 @@ Manager* manager_free(Manager *manager) {
udev_builtin_exit();
hashmap_free_free_free(manager->properties);
hashmap_free(manager->properties);
udev_rules_free(manager->rules);
hashmap_free(manager->workers);
+8 -8
View File
@@ -467,8 +467,8 @@ UdevRules* udev_rules_free(UdevRules *rules) {
LIST_FOREACH(rule_files, i, rules->rule_files)
udev_rule_file_free(i);
hashmap_free_free_key(rules->known_users);
hashmap_free_free_key(rules->known_groups);
hashmap_free(rules->known_users);
hashmap_free(rules->known_groups);
hashmap_free(rules->stats_by_path);
return mfree(rules);
}
@@ -504,7 +504,7 @@ static int rule_resolve_user(UdevRuleLine *rule_line, const char *name, uid_t *r
if (!n)
return -ENOMEM;
r = hashmap_ensure_put(known_users, &string_hash_ops, n, UID_TO_PTR(uid));
r = hashmap_ensure_put(known_users, &string_hash_ops_free, n, UID_TO_PTR(uid));
if (r < 0)
return r;
@@ -544,7 +544,7 @@ static int rule_resolve_group(UdevRuleLine *rule_line, const char *name, gid_t *
if (!n)
return -ENOMEM;
r = hashmap_ensure_put(known_groups, &string_hash_ops, n, GID_TO_PTR(gid));
r = hashmap_ensure_put(known_groups, &string_hash_ops_free, n, GID_TO_PTR(gid));
if (r < 0)
return r;
@@ -2756,9 +2756,9 @@ static int udev_rule_apply_token_to_event(
return log_oom();
if (token->op == OP_ASSIGN)
ordered_hashmap_clear_free_free(event->seclabel_list);
ordered_hashmap_clear(event->seclabel_list);
r = ordered_hashmap_ensure_put(&event->seclabel_list, NULL, name, label);
r = ordered_hashmap_ensure_put(&event->seclabel_list, &trivial_hash_ops_free_free, name, label);
if (r == -ENOMEM)
return log_oom();
if (r < 0)
@@ -3021,7 +3021,7 @@ static int udev_rule_apply_token_to_event(
event->run_final = true;
if (IN_SET(token->op, OP_ASSIGN, OP_ASSIGN_FINAL))
ordered_hashmap_clear_free_key(event->run_list);
ordered_hashmap_clear(event->run_list);
if (!apply_format_value(event, token, buf, sizeof(buf), "command"))
return true;
@@ -3030,7 +3030,7 @@ static int udev_rule_apply_token_to_event(
if (!cmd)
return log_oom();
r = ordered_hashmap_ensure_put(&event->run_list, NULL, cmd, token->data);
r = ordered_hashmap_ensure_put(&event->run_list, &trivial_hash_ops_free, cmd, token->data);
if (r < 0)
return log_event_error_errno(event, token, r, "Failed to store command \"%s\": %m", cmd);