From 30e2c8c7e87c52045357a0031365a871b66ab449 Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Fri, 5 Mar 2021 06:39:16 +0900 Subject: [PATCH] sd-device-enumerator: add comments why trivial_hash_ops_free_free is used Follow-up for a0887abbd8bd9f1a9a975af08e6b4a43960bb3e2. --- src/libsystemd/sd-device/device-enumerator.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/libsystemd/sd-device/device-enumerator.c b/src/libsystemd/sd-device/device-enumerator.c index c98b029af23..2434fb625e5 100644 --- a/src/libsystemd/sd-device/device-enumerator.c +++ b/src/libsystemd/sd-device/device-enumerator.c @@ -116,6 +116,8 @@ _public_ int sd_device_enumerator_add_match_sysattr(sd_device_enumerator *enumer else hashmap = &enumerator->nomatch_sysattr; + /* Do not use string_has_ops_free_free or hashmap_put_strdup() here, as this may be called + * multiple times with the same sysattr but different value. */ r = hashmap_put_strdup_full(hashmap, &trivial_hash_ops_free_free, sysattr, value); if (r <= 0) return r; @@ -131,6 +133,8 @@ _public_ int sd_device_enumerator_add_match_property(sd_device_enumerator *enume assert_return(enumerator, -EINVAL); assert_return(property, -EINVAL); + /* Do not use string_has_ops_free_free or hashmap_put_strdup() here, as this may be called + * multiple times with the same property but different value. */ r = hashmap_put_strdup_full(&enumerator->match_property, &trivial_hash_ops_free_free, property, value); if (r <= 0) return r; -- 2.39.2