dhcp: don't destroy old value before setting new in nm_dhcp_client_set_effective_client_id()

Of course, the old "priv->effective_client_id" and the new
"client_id" instances are truly separate, that is, they don't
share data, and destroying "priv->effective_client_id" before
taking a reference on "client_id" causes no problem.

It's still a code smell. It makes the function unnecessarily unsafe
under (very unusual) circumstances.

(cherry picked from commit a3e4f764d1)
This commit is contained in:
Thomas Haller 2022-12-14 08:58:36 +01:00
parent 1f30005d5e
commit 919d66f049
No known key found for this signature in database
GPG key ID: 29C2366E4DFC5728

View file

@ -274,8 +274,9 @@ nm_dhcp_client_create_options_dict(NMDhcpClient *self, gboolean static_keys)
gboolean
nm_dhcp_client_set_effective_client_id(NMDhcpClient *self, GBytes *client_id)
{
NMDhcpClientPrivate *priv = NM_DHCP_CLIENT_GET_PRIVATE(self);
gs_free char *tmp_str = NULL;
NMDhcpClientPrivate *priv = NM_DHCP_CLIENT_GET_PRIVATE(self);
gs_free char *tmp_str = NULL;
gs_unref_bytes GBytes *client_id_to_free = NULL;
g_return_val_if_fail(NM_IS_DHCP_CLIENT(self), FALSE);
g_return_val_if_fail(!client_id || g_bytes_get_size(client_id) >= 2, FALSE);
@ -285,7 +286,7 @@ nm_dhcp_client_set_effective_client_id(NMDhcpClient *self, GBytes *client_id)
if (nm_g_bytes_equal0(priv->effective_client_id, client_id))
return FALSE;
g_bytes_unref(priv->effective_client_id);
client_id_to_free = g_steal_pointer(&priv->effective_client_id);
priv->effective_client_id = nm_g_bytes_ref(client_id);
_LOGT("%s: set effective %s",