From 41ced630fbdd4f42aaa35b6e9a1fc206ab8c3ebf Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Wed, 23 Apr 2014 12:48:14 +0200 Subject: [PATCH] libnm-glib: fix resetting IP config during additional SetConfig() calls When receiving updated VPN IP configuration from the helper after the initial connect event, the library overwrites the already initialized GValue fields by calling g_value_init() again. This is an error and causes the following warning: (nm-openvpn-service:27645): GLib-GObject-WARNING **: gvalue.c:183: cannot initialize GValue with type gchararray, the value has already been initialized as gchararray Signed-off-by: Thomas Haller --- libnm-glib/nm-vpn-plugin.c | 38 ++++++++++++++++++-------------------- 1 file changed, 18 insertions(+), 20 deletions(-) diff --git a/libnm-glib/nm-vpn-plugin.c b/libnm-glib/nm-vpn-plugin.c index d5a2b69c7..d52416969 100644 --- a/libnm-glib/nm-vpn-plugin.c +++ b/libnm-glib/nm-vpn-plugin.c @@ -296,6 +296,20 @@ schedule_fail_stop (NMVPNPlugin *plugin) priv->fail_stop_id = g_idle_add (fail_stop, plugin); } +static void +_g_value_set (GValue *dst, GValue *src) +{ + if (src) { + GType type = G_VALUE_TYPE (src); + + if (G_IS_VALUE (dst)) + g_value_unset (dst); + g_value_init (dst, type); + g_value_copy (src, dst); + } else if (G_IS_VALUE (dst)) + g_value_unset (dst); +} + void nm_vpn_plugin_set_config (NMVPNPlugin *plugin, GHashTable *config) @@ -320,26 +334,10 @@ nm_vpn_plugin_set_config (NMVPNPlugin *plugin, /* Record the items that need to also be inserted into the * ip4config, for compatibility with older daemons. */ - val = g_hash_table_lookup (config, NM_VPN_PLUGIN_CONFIG_BANNER); - if (val) { - g_value_init (&priv->banner, G_VALUE_TYPE (val)); - g_value_copy (val, &priv->banner); - } - val = g_hash_table_lookup (config, NM_VPN_PLUGIN_CONFIG_TUNDEV); - if (val) { - g_value_init (&priv->tundev, G_VALUE_TYPE (val)); - g_value_copy (val, &priv->tundev); - } - val = g_hash_table_lookup (config, NM_VPN_PLUGIN_CONFIG_EXT_GATEWAY); - if (val) { - g_value_init (&priv->gateway, G_VALUE_TYPE (val)); - g_value_copy (val, &priv->gateway); - } - val = g_hash_table_lookup (config, NM_VPN_PLUGIN_CONFIG_MTU); - if (val) { - g_value_init (&priv->mtu, G_VALUE_TYPE (val)); - g_value_copy (val, &priv->mtu); - } + _g_value_set (&priv->banner, g_hash_table_lookup (config, NM_VPN_PLUGIN_CONFIG_BANNER)); + _g_value_set (&priv->tundev, g_hash_table_lookup (config, NM_VPN_PLUGIN_CONFIG_TUNDEV)); + _g_value_set (&priv->gateway, g_hash_table_lookup (config, NM_VPN_PLUGIN_CONFIG_EXT_GATEWAY)); + _g_value_set (&priv->mtu, g_hash_table_lookup (config, NM_VPN_PLUGIN_CONFIG_MTU)); g_signal_emit (plugin, signals[CONFIG], 0, config); }