]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
udev: use hash ops with destructor
authorYu Watanabe <watanabe.yu+github@gmail.com>
Wed, 22 Jan 2025 02:08:07 +0000 (11:08 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Thu, 23 Jan 2025 09:19:28 +0000 (18:19 +0900)
src/udev/udev-config.c
src/udev/udev-event.c
src/udev/udev-manager.c
src/udev/udev-rules.c

index 6f02d25f455c96aeae120d66a39f7cc9027e2046..6562b34d2f861a9adefed914ad87942c5c1ffae0 100644 (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);
index fc4c9f9fd1b1fd01dc1a37ea8d38b9cbfc59a9f9..7d9153061f7ba0a80ee4ed2211cced4ebd0dc4d7 100644 (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);
index 873a076a2d9f39375384dbbc5b963a03c36a3901..97465b796d698d003aeb528d12059fcb64e91a93 100644 (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);
index ec4660968cdddd972f511bb1f90c5f611ab41a34..6c5c0f4533eacde2eb60768dd5e17c7c9455e4eb 100644 (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);