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 commit 0fbb54839e
)
This commit is contained in:
@@ -224,7 +224,7 @@ _lldp_attr_set_str (LldpAttrData *pdata, LldpAttrId attr_id, const char *v_strin
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
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 (pdata);
|
||||||
nm_assert (_lldp_attr_id_to_type (attr_id) == LLDP_ATTR_TYPE_STRING);
|
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 */
|
/* we ignore duplicate fields silently */
|
||||||
if (pdata->attr_type != LLDP_ATTR_TYPE_NONE) {
|
if (pdata->attr_type != LLDP_ATTR_TYPE_NONE) {
|
||||||
if (g_variant_is_floating (variant))
|
nm_g_variant_unref_floating (variant);
|
||||||
g_variant_unref (variant);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -687,9 +686,10 @@ lldp_neighbor_new (sd_lldp_neighbor *neighbor_sd, GError **error)
|
|||||||
g_variant_dict_end (&dict));
|
g_variant_dict_end (&dict));
|
||||||
|
|
||||||
_lldp_attr_set_uint32 (neigh->attrs, LLDP_ATTR_ID_IEEE_802_1_VID, vid);
|
_lldp_attr_set_uint32 (neigh->attrs, LLDP_ATTR_ID_IEEE_802_1_VID, vid);
|
||||||
_lldp_attr_take_str_ptr (neigh->attrs,
|
if (name_to_free)
|
||||||
LLDP_ATTR_ID_IEEE_802_1_VLAN_NAME,
|
_lldp_attr_set_str_take (neigh->attrs, LLDP_ATTR_ID_IEEE_802_1_VLAN_NAME, name_to_free);
|
||||||
name_to_free ?: g_strdup (name));
|
else
|
||||||
|
_lldp_attr_set_str (neigh->attrs, LLDP_ATTR_ID_IEEE_802_1_VLAN_NAME, name);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
|
Reference in New Issue
Block a user