From: Yu Watanabe Date: Sat, 12 Apr 2025 03:06:19 +0000 (+0900) Subject: libudev-list: use custom hash_ops with destructor for udev_list_entry X-Git-Tag: v258-rc1~792^2~3 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=76a8f5ae4b6c5885231a688d0f143adbc13bd22b;p=thirdparty%2Fsystemd.git libudev-list: use custom hash_ops with destructor for udev_list_entry --- diff --git a/src/libudev/libudev-list.c b/src/libudev/libudev-list.c index 0adc1d58e3d..12d86210922 100644 --- a/src/libudev/libudev-list.c +++ b/src/libudev/libudev-list.c @@ -54,6 +54,11 @@ static struct udev_list_entry *udev_list_entry_free(struct udev_list_entry *entr DEFINE_TRIVIAL_CLEANUP_FUNC(struct udev_list_entry *, udev_list_entry_free); +DEFINE_PRIVATE_HASH_OPS_WITH_VALUE_DESTRUCTOR( + udev_list_entry_hash_ops, + char, string_hash_func, string_compare_func, + struct udev_list_entry, udev_list_entry_free); + struct udev_list *udev_list_new(bool unique) { struct udev_list *list; @@ -97,7 +102,7 @@ struct udev_list_entry *udev_list_entry_add(struct udev_list *list, const char * if (list->unique) { udev_list_entry_free(hashmap_get(list->unique_entries, entry->name)); - if (hashmap_ensure_put(&list->unique_entries, &string_hash_ops, entry->name, entry) < 0) + if (hashmap_ensure_put(&list->unique_entries, &udev_list_entry_hash_ops, entry->name, entry) < 0) return NULL; list->uptodate = false; @@ -115,7 +120,7 @@ void udev_list_cleanup(struct udev_list *list) { if (list->unique) { list->uptodate = false; - hashmap_clear_with_destructor(list->unique_entries, udev_list_entry_free); + hashmap_clear(list->unique_entries); } else LIST_FOREACH(entries, i, list->entries) udev_list_entry_free(i);