From 0fbb54839e3f1b5309fa3d81cf8821b2fa1ed1e0 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Thu, 1 Aug 2019 15:05:27 +0200 Subject: [PATCH] core/lldp: minor cleanup in _lldp_attr_*() - use nm_g_variant_unref_floating() - rename _lldp_attr_take_str_ptr() to _lldp_attr_set_str_take(). The new name has the same "_lldp_attr_set_" prefix as other setters. Also, with the previous name it is unclear why it takes a "str-ptr". - setting the same attribute multiple times, ignores all but the first value. Avoid cloning the string in that case, and explicitly choose the set or take function. --- src/devices/nm-lldp-listener.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/devices/nm-lldp-listener.c b/src/devices/nm-lldp-listener.c index 2dc38d4ca8..469ccce165 100644 --- a/src/devices/nm-lldp-listener.c +++ b/src/devices/nm-lldp-listener.c @@ -224,7 +224,7 @@ _lldp_attr_set_str (LldpAttrData *pdata, LldpAttrId attr_id, const char *v_strin } static void -_lldp_attr_take_str_ptr (LldpAttrData *pdata, LldpAttrId attr_id, char *str) +_lldp_attr_set_str_take (LldpAttrData *pdata, LldpAttrId attr_id, char *str) { nm_assert (pdata); nm_assert (_lldp_attr_id_to_type (attr_id) == LLDP_ATTR_TYPE_STRING); @@ -267,8 +267,7 @@ _lldp_attr_set_vardict (LldpAttrData *pdata, LldpAttrId attr_id, GVariant *varia /* we ignore duplicate fields silently */ if (pdata->attr_type != LLDP_ATTR_TYPE_NONE) { - if (g_variant_is_floating (variant)) - g_variant_unref (variant); + nm_g_variant_unref_floating (variant); return; } @@ -687,9 +686,10 @@ lldp_neighbor_new (sd_lldp_neighbor *neighbor_sd, GError **error) g_variant_dict_end (&dict)); _lldp_attr_set_uint32 (neigh->attrs, LLDP_ATTR_ID_IEEE_802_1_VID, vid); - _lldp_attr_take_str_ptr (neigh->attrs, - LLDP_ATTR_ID_IEEE_802_1_VLAN_NAME, - name_to_free ?: g_strdup (name)); + if (name_to_free) + _lldp_attr_set_str_take (neigh->attrs, LLDP_ATTR_ID_IEEE_802_1_VLAN_NAME, name_to_free); + else + _lldp_attr_set_str (neigh->attrs, LLDP_ATTR_ID_IEEE_802_1_VLAN_NAME, name); break; } default: