From: Yu Watanabe Date: Sat, 12 Apr 2025 02:47:22 +0000 (+0900) Subject: sd-device-enumerator: use custom hash_ops with destructor X-Git-Tag: v258-rc1~791^2~3 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=70669fa2fe040f20ac0a5a8f554f0f26f1505aae;p=thirdparty%2Fsystemd.git sd-device-enumerator: use custom hash_ops with destructor --- diff --git a/src/libsystemd/sd-device/device-enumerator.c b/src/libsystemd/sd-device/device-enumerator.c index ca7e70393b8..b72a2463dab 100644 --- a/src/libsystemd/sd-device/device-enumerator.c +++ b/src/libsystemd/sd-device/device-enumerator.c @@ -91,7 +91,7 @@ static void device_unref_many(sd_device **devices, size_t n) { static void device_enumerator_unref_devices(sd_device_enumerator *enumerator) { assert(enumerator); - hashmap_clear_with_destructor(enumerator->devices_by_syspath, sd_device_unref); + hashmap_clear(enumerator->devices_by_syspath); device_unref_many(enumerator->devices, enumerator->n_devices); enumerator->devices = mfree(enumerator->devices); enumerator->n_devices = 0; @@ -471,6 +471,11 @@ failed: return r; } +DEFINE_PRIVATE_HASH_OPS_WITH_VALUE_DESTRUCTOR( + device_hash_ops_by_syspath, + char, path_hash_func, path_compare, + sd_device, sd_device_unref); + int device_enumerator_add_device(sd_device_enumerator *enumerator, sd_device *device) { const char *syspath; int r; @@ -482,7 +487,7 @@ int device_enumerator_add_device(sd_device_enumerator *enumerator, sd_device *de if (r < 0) return r; - r = hashmap_ensure_put(&enumerator->devices_by_syspath, &string_hash_ops, syspath, device); + r = hashmap_ensure_put(&enumerator->devices_by_syspath, &device_hash_ops_by_syspath, syspath, device); if (IN_SET(r, -EEXIST, 0)) return 0; if (r < 0)