diff options
author | Thomas Haller <thaller@redhat.com> | 2018-05-25 11:03:48 +0200 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2018-05-26 20:11:04 +0200 |
commit | ef8782127f2a91ee75cbdeeba257c489eb5bec9f (patch) | |
tree | f7bbfc32ade536fd638435aa9f2139c447737243 | |
parent | 97dc1ec1e4026e9bd41db73e6ce318097e192612 (diff) | |
download | NetworkManager-ef8782127f2a91ee75cbdeeba257c489eb5bec9f.tar.gz |
dhcp: use cleanup attribute in nm_dhcp_client_handle_event()
and use NMIPConfig type.
-rw-r--r-- | src/dhcp/nm-dhcp-client.c | 41 |
1 files changed, 19 insertions, 22 deletions
diff --git a/src/dhcp/nm-dhcp-client.c b/src/dhcp/nm-dhcp-client.c index 7d42a786ec..f1a62f2474 100644 --- a/src/dhcp/nm-dhcp-client.c +++ b/src/dhcp/nm-dhcp-client.c @@ -770,8 +770,8 @@ nm_dhcp_client_handle_event (gpointer unused, NMDhcpClientPrivate *priv; guint32 old_state; guint32 new_state; - GHashTable *str_options = NULL; - GObject *ip_config = NULL; + gs_unref_hashtable GHashTable *str_options = NULL; + gs_unref_object NMIPConfig *ip_config = NULL; NMPlatformIP6Address prefix = { 0, }; g_return_val_if_fail (NM_IS_DHCP_CLIENT (self), FALSE); @@ -815,24 +815,24 @@ nm_dhcp_client_handle_event (gpointer unused, } /* Create the IP config */ - g_warn_if_fail (g_hash_table_size (str_options)); - if (g_hash_table_size (str_options)) { + if (g_hash_table_size (str_options) > 0) { if (priv->addr_family == AF_INET) { - ip_config = (GObject *) nm_dhcp_utils_ip4_config_from_options (nm_dhcp_client_get_multi_idx (self), - priv->ifindex, - priv->iface, - str_options, - priv->route_table, - priv->route_metric); + ip_config = NM_IP_CONFIG_CAST (nm_dhcp_utils_ip4_config_from_options (nm_dhcp_client_get_multi_idx (self), + priv->ifindex, + priv->iface, + str_options, + priv->route_table, + priv->route_metric)); } else { prefix = nm_dhcp_utils_ip6_prefix_from_options (str_options); - ip_config = (GObject *) nm_dhcp_utils_ip6_config_from_options (nm_dhcp_client_get_multi_idx (self), - priv->ifindex, - priv->iface, - str_options, - priv->info_only); + ip_config = NM_IP_CONFIG_CAST (nm_dhcp_utils_ip6_config_from_options (nm_dhcp_client_get_multi_idx (self), + priv->ifindex, + priv->iface, + str_options, + priv->info_only)); } - } + } else + g_warn_if_reached (); } if (!IN6_IS_ADDR_UNSPECIFIED (&prefix.address)) { @@ -844,19 +844,16 @@ nm_dhcp_client_handle_event (gpointer unused, &prefix); } else { /* Fail if no valid IP config was received */ - if (new_state == NM_DHCP_STATE_BOUND && ip_config == NULL) { + if ( new_state == NM_DHCP_STATE_BOUND + && !ip_config) { _LOGW ("client bound but IP config not received"); new_state = NM_DHCP_STATE_FAIL; g_clear_pointer (&str_options, g_hash_table_unref); } - nm_dhcp_client_set_state (self, new_state, ip_config, str_options); + nm_dhcp_client_set_state (self, new_state, G_OBJECT (ip_config), str_options); } - if (str_options) - g_hash_table_destroy (str_options); - g_clear_object (&ip_config); - return TRUE; } |