mirror of
https://github.com/systemd/systemd-stable.git
synced 2025-03-10 00:58:20 +03:00
sd-device: use string_hash_ops_free_free
This commit is contained in:
parent
327379f5f2
commit
61c0972dad
@ -67,7 +67,7 @@ static sd_device *device_free(sd_device *device) {
|
||||
|
||||
ordered_hashmap_free(device->properties);
|
||||
ordered_hashmap_free(device->properties_db);
|
||||
hashmap_free_free_free(device->sysattr_values);
|
||||
hashmap_free(device->sysattr_values);
|
||||
set_free(device->sysattrs);
|
||||
set_free(device->all_tags);
|
||||
set_free(device->current_tags);
|
||||
@ -1780,30 +1780,28 @@ _public_ int sd_device_get_property_value(sd_device *device, const char *key, co
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* replaces the value if it already exists */
|
||||
static int device_add_sysattr_value(sd_device *device, const char *_key, char *value) {
|
||||
_cleanup_free_ char *key = NULL;
|
||||
_cleanup_free_ char *value_old = NULL;
|
||||
static int device_add_sysattr_value(sd_device *device, const char *key, char *value) {
|
||||
_cleanup_free_ char *new_key = NULL, *old_value = NULL;
|
||||
int r;
|
||||
|
||||
assert(device);
|
||||
assert(_key);
|
||||
assert(key);
|
||||
|
||||
r = hashmap_ensure_allocated(&device->sysattr_values, &string_hash_ops);
|
||||
if (r < 0)
|
||||
return r;
|
||||
/* This takes the reference of the input value. The input value may be NULL.
|
||||
* This replaces the value if it already exists. */
|
||||
|
||||
value_old = hashmap_remove2(device->sysattr_values, _key, (void **)&key);
|
||||
if (!key) {
|
||||
key = strdup(_key);
|
||||
if (!key)
|
||||
old_value = hashmap_remove2(device->sysattr_values, key, (void **) &new_key);
|
||||
if (!new_key) {
|
||||
new_key = strdup(key);
|
||||
if (!new_key)
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
r = hashmap_put(device->sysattr_values, key, value);
|
||||
r = hashmap_ensure_put(&device->sysattr_values, &string_hash_ops_free_free, new_key, value);
|
||||
if (r < 0)
|
||||
return r;
|
||||
TAKE_PTR(key);
|
||||
|
||||
TAKE_PTR(new_key);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user