summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2021-02-02 15:05:46 +0100
committerGitHub <noreply@github.com>2021-02-02 15:05:46 +0100
commitedf370af9e9fafad01393699e7a6f34bf0568dd6 (patch)
tree4cb4324c68553c9e2720e6fb68dca20221be00c8 /src
parent8885fed4e3a52cf1bf105e42043203c485ed9d92 (diff)
parentecf83c24295bbb7b940c91fb2aab387db74ef685 (diff)
downloadsystemd-edf370af9e9fafad01393699e7a6f34bf0568dd6.tar.gz
Merge pull request #18432 from yuwata/libude-list-cleanups
libudev: cleanups for libudev-list
Diffstat (limited to 'src')
-rw-r--r--src/libudev/libudev-list.c19
1 files changed, 8 insertions, 11 deletions
diff --git a/src/libudev/libudev-list.c b/src/libudev/libudev-list.c
index 3b2a2cdee4..69efc1013c 100644
--- a/src/libudev/libudev-list.c
+++ b/src/libudev/libudev-list.c
@@ -39,9 +39,10 @@ static struct udev_list_entry *udev_list_entry_free(struct udev_list_entry *entr
return NULL;
if (entry->list) {
- if (entry->list->unique)
+ if (entry->list->unique && entry->name)
hashmap_remove(entry->list->unique_entries, entry->name);
- else
+
+ if (!entry->list->unique || entry->list->uptodate)
LIST_REMOVE(entries, entry->list->entries, entry);
}
@@ -70,9 +71,9 @@ struct udev_list *udev_list_new(bool unique) {
struct udev_list_entry *udev_list_entry_add(struct udev_list *list, const char *_name, const char *_value) {
_cleanup_(udev_list_entry_freep) struct udev_list_entry *entry = NULL;
_cleanup_free_ char *name = NULL, *value = NULL;
- int r;
assert(list);
+ assert(_name);
name = strdup(_name);
if (!name)
@@ -89,26 +90,22 @@ struct udev_list_entry *udev_list_entry_add(struct udev_list *list, const char *
return NULL;
*entry = (struct udev_list_entry) {
- .list = list,
.name = TAKE_PTR(name),
.value = TAKE_PTR(value),
};
if (list->unique) {
- r = hashmap_ensure_allocated(&list->unique_entries, &string_hash_ops);
- if (r < 0)
- return NULL;
-
udev_list_entry_free(hashmap_get(list->unique_entries, entry->name));
- r = hashmap_put(list->unique_entries, entry->name, entry);
- if (r < 0)
+ if (hashmap_ensure_put(&list->unique_entries, &string_hash_ops, entry->name, entry) < 0)
return NULL;
list->uptodate = false;
} else
LIST_APPEND(entries, list->entries, entry);
+ entry->list = list;
+
return TAKE_PTR(entry);
}
@@ -119,8 +116,8 @@ void udev_list_cleanup(struct udev_list *list) {
return;
if (list->unique) {
- hashmap_clear_with_destructor(list->unique_entries, udev_list_entry_free);
list->uptodate = false;
+ hashmap_clear_with_destructor(list->unique_entries, udev_list_entry_free);
} else
LIST_FOREACH_SAFE(entries, i, n, list->entries)
udev_list_entry_free(i);