Skip to content

Commit 76a8f5a

Browse files
committed
libudev-list: use custom hash_ops with destructor for udev_list_entry
1 parent 9f091f0 commit 76a8f5a

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/libudev/libudev-list.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,11 @@ static struct udev_list_entry *udev_list_entry_free(struct udev_list_entry *entr
5454

5555
DEFINE_TRIVIAL_CLEANUP_FUNC(struct udev_list_entry *, udev_list_entry_free);
5656

57+
DEFINE_PRIVATE_HASH_OPS_WITH_VALUE_DESTRUCTOR(
58+
udev_list_entry_hash_ops,
59+
char, string_hash_func, string_compare_func,
60+
struct udev_list_entry, udev_list_entry_free);
61+
5762
struct udev_list *udev_list_new(bool unique) {
5863
struct udev_list *list;
5964

@@ -97,7 +102,7 @@ struct udev_list_entry *udev_list_entry_add(struct udev_list *list, const char *
97102
if (list->unique) {
98103
udev_list_entry_free(hashmap_get(list->unique_entries, entry->name));
99104

100-
if (hashmap_ensure_put(&list->unique_entries, &string_hash_ops, entry->name, entry) < 0)
105+
if (hashmap_ensure_put(&list->unique_entries, &udev_list_entry_hash_ops, entry->name, entry) < 0)
101106
return NULL;
102107

103108
list->uptodate = false;
@@ -115,7 +120,7 @@ void udev_list_cleanup(struct udev_list *list) {
115120

116121
if (list->unique) {
117122
list->uptodate = false;
118-
hashmap_clear_with_destructor(list->unique_entries, udev_list_entry_free);
123+
hashmap_clear(list->unique_entries);
119124
} else
120125
LIST_FOREACH(entries, i, list->entries)
121126
udev_list_entry_free(i);

0 commit comments

Comments
 (0)