From: Zbigniew Jędrzejewski-Szmek Date: Wed, 29 Apr 2020 12:28:56 +0000 (+0200) Subject: sd-device: use hashmap_put_strdup() X-Git-Tag: v246-rc1~418^2~4 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=eb1c1dc029c91750e6255c3fd844b4f4bf238fab;p=thirdparty%2Fsystemd.git sd-device: use hashmap_put_strdup() --- diff --git a/src/libsystemd/sd-device/device-enumerator.c b/src/libsystemd/sd-device/device-enumerator.c index d6ceb2aff38..f9b14f2ffb4 100644 --- a/src/libsystemd/sd-device/device-enumerator.c +++ b/src/libsystemd/sd-device/device-enumerator.c @@ -73,9 +73,9 @@ static sd_device_enumerator *device_enumerator_free(sd_device_enumerator *enumer free(enumerator->devices); set_free(enumerator->match_subsystem); set_free(enumerator->nomatch_subsystem); - hashmap_free_free_free(enumerator->match_sysattr); - hashmap_free_free_free(enumerator->nomatch_sysattr); - hashmap_free_free_free(enumerator->match_property); + hashmap_free(enumerator->match_sysattr); + hashmap_free(enumerator->nomatch_sysattr); + hashmap_free(enumerator->match_property); set_free(enumerator->match_sysname); set_free(enumerator->match_tag); set_free(enumerator->match_parent); @@ -106,73 +106,37 @@ _public_ int sd_device_enumerator_add_match_subsystem(sd_device_enumerator *enum return 0; } -_public_ int sd_device_enumerator_add_match_sysattr(sd_device_enumerator *enumerator, const char *_sysattr, const char *_value, int match) { - _cleanup_free_ char *sysattr = NULL, *value = NULL; +_public_ int sd_device_enumerator_add_match_sysattr(sd_device_enumerator *enumerator, const char *sysattr, const char *value, int match) { Hashmap **hashmap; int r; assert_return(enumerator, -EINVAL); - assert_return(_sysattr, -EINVAL); + assert_return(sysattr, -EINVAL); if (match) hashmap = &enumerator->match_sysattr; else hashmap = &enumerator->nomatch_sysattr; - r = hashmap_ensure_allocated(hashmap, NULL); + r = hashmap_put_strdup(hashmap, sysattr, value); if (r < 0) return r; - sysattr = strdup(_sysattr); - if (!sysattr) - return -ENOMEM; - - if (_value) { - value = strdup(_value); - if (!value) - return -ENOMEM; - } - - r = hashmap_put(*hashmap, sysattr, value); - if (r < 0) - return r; - - sysattr = NULL; - value = NULL; - enumerator->scan_uptodate = false; return 0; } -_public_ int sd_device_enumerator_add_match_property(sd_device_enumerator *enumerator, const char *_property, const char *_value) { - _cleanup_free_ char *property = NULL, *value = NULL; +_public_ int sd_device_enumerator_add_match_property(sd_device_enumerator *enumerator, const char *property, const char *value) { int r; assert_return(enumerator, -EINVAL); - assert_return(_property, -EINVAL); + assert_return(property, -EINVAL); - r = hashmap_ensure_allocated(&enumerator->match_property, NULL); + r = hashmap_put_strdup(&enumerator->match_property, property, value); if (r < 0) return r; - property = strdup(_property); - if (!property) - return -ENOMEM; - - if (_value) { - value = strdup(_value); - if (!value) - return -ENOMEM; - } - - r = hashmap_put(enumerator->match_property, property, value); - if (r < 0) - return r; - - property = NULL; - value = NULL; - enumerator->scan_uptodate = false; return 0;