mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-03-06 22:10:33 +01:00
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. (cherry picked from commit0fbb54839e) (cherry picked from commitd84d1db39e)
This commit is contained in:
parent
5233a02e28
commit
134ccb4a17
1 changed files with 6 additions and 6 deletions
|
|
@ -225,7 +225,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);
|
||||
|
|
@ -268,8 +268,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;
|
||||
}
|
||||
|
||||
|
|
@ -688,9 +687,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:
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue