Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[gsupplicant] Compatibility with glib 2.56. JB#41420
If the stubs are generated by gdbus-codegen < 2.56 then strv getters
return shallow copy, i.e. the return result should be released with
g_free(), but the individual strings must not be modified. Luckily,
this can be determined at compile time.

See https://bugzilla.gnome.org/show_bug.cgi?id=770335
  • Loading branch information
monich committed May 28, 2018
1 parent 553ec45 commit dcf430e
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 40 deletions.
19 changes: 12 additions & 7 deletions src/gsupplicant.c
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2015-2017 Jolla Ltd.
* Copyright (C) 2015-2018 Jolla Ltd.
* Contact: Slava Monich <slava.monich@jolla.com>
*
* You may use this file under the terms of BSD license as follows:
Expand Down Expand Up @@ -453,24 +453,29 @@ gsupplicant_update_interfaces(
GSupplicant* self)
{
GSupplicantPriv* priv = self->priv;
/*
* g_variant_get_objv returns shallow copy, i.e. the return
* result should be released with g_free(), but the individual
* strings must not be modified.
*/
gchar** interfaces = (char**)(self->valid ?
fi_w1_wpa_supplicant1_get_interfaces(priv->proxy) : NULL);
/* If the stub is generated by gdbus-codegen < 2.56 then the getting
* returns shallow copy, i.e. the return result should be released
* with g_free(), but the individual strings must not be modified. */
if (!gutil_strv_equal((const GStrV*)interfaces, priv->interfaces)) {
#if STRV_GETTERS_RETURN_SHALLOW_COPY
GStrV* ptr;
for (ptr = interfaces; *ptr; ptr++) {
*ptr = g_strdup(*ptr);
}
#else
interfaces = g_strdupv(interfaces);
#endif
g_strfreev(priv->interfaces);
self->interfaces = priv->interfaces = interfaces;
priv->pending_signals |= SIGNAL_BIT(INTERFACES);
} else {
}
#if STRV_GETTERS_RETURN_SHALLOW_COPY
else {
g_free(interfaces);
}
#endif
}

static
Expand Down
12 changes: 11 additions & 1 deletion src/gsupplicant_dbus.h
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2015-2017 Jolla Ltd.
* Copyright (C) 2015-2018 Jolla Ltd.
* Contact: Slava Monich <slava.monich@jolla.com>
*
* You may use this file under the terms of BSD license as follows:
Expand Down Expand Up @@ -40,6 +40,16 @@
#define GSUPPLICANT_SERVICE "fi.w1.wpa_supplicant1"
#define GSUPPLICANT_PATH "/fi/w1/wpa_supplicant1"

/*
* If the stubs are generated by gdbus-codegen < 2.56 then strv getters
* return shallow copy, i.e. the return result should be released with
* g_free(), but the individual strings must not be modified. Luckily,
* this can be determined at compile time.
*
* See https://bugzilla.gnome.org/show_bug.cgi?id=770335
*/
#define STRV_GETTERS_RETURN_SHALLOW_COPY !GLIB_CHECK_VERSION(2,56,0)

#endif /* GSUPPLICANT_DBUS_H */

/*
Expand Down
74 changes: 42 additions & 32 deletions src/gsupplicant_interface.c
Expand Up @@ -1711,24 +1711,29 @@ gsupplicant_interface_update_bsss(
GSupplicantInterface* self)
{
GSupplicantInterfacePriv* priv = self->priv;
/*
* g_variant_get_objv returns shallow copy, i.e. the return
* result should be released with g_free(), but the individual
* strings must not be modified.
*/
gchar** bsss = (char**)(self->valid ?
fi_w1_wpa_supplicant1_interface_get_bsss(priv->proxy) : NULL);
if (!gutil_strv_equal((const GStrV*)bsss, priv->bsss)) {
GStrV* ptr;
for (ptr = bsss; *ptr; ptr++) {
*ptr = g_strdup(*ptr);
}
g_strfreev(priv->bsss);
self->bsss = priv->bsss = bsss;
priv->pending_signals |= SIGNAL_BIT(BSSS);
} else {
g_free(bsss);
}
/* If the stub is generated by gdbus-codegen < 2.56 then the getting
* returns shallow copy, i.e. the return result should be released
* with g_free(), but the individual strings must not be modified. */
if (!gutil_strv_equal((const GStrV*)bsss, priv->bsss)) {
#if STRV_GETTERS_RETURN_SHALLOW_COPY
GStrV* ptr;
for (ptr = bsss; *ptr; ptr++) {
*ptr = g_strdup(*ptr);
}
#else
bsss = g_strdupv(bsss);
#endif
g_strfreev(priv->bsss);
self->bsss = priv->bsss = bsss;
priv->pending_signals |= SIGNAL_BIT(BSSS);
}
#if STRV_GETTERS_RETURN_SHALLOW_COPY
else {
g_free(bsss);
}
#endif
}

static
Expand All @@ -1737,24 +1742,29 @@ gsupplicant_interface_update_networks(
GSupplicantInterface* self)
{
GSupplicantInterfacePriv* priv = self->priv;
/*
* g_variant_get_objv returns shallow copy, i.e. the return
* result should be released with g_free(), but the individual
* strings must not be modified.
*/
gchar** networks = (char**)(self->valid ?
fi_w1_wpa_supplicant1_interface_get_networks(priv->proxy) : NULL);
if (!gutil_strv_equal((const GStrV*)networks, priv->networks)) {
GStrV* ptr;
for (ptr = networks; *ptr; ptr++) {
*ptr = g_strdup(*ptr);
}
g_strfreev(priv->networks);
self->networks = priv->networks = networks;
priv->pending_signals |= SIGNAL_BIT(NETWORKS);
} else {
g_free(networks);
}
/* If the stub is generated by gdbus-codegen < 2.56 then the getting
* returns shallow copy, i.e. the return result should be released
* with g_free(), but the individual strings must not be modified. */
if (!gutil_strv_equal((const GStrV*)networks, priv->networks)) {
#if STRV_GETTERS_RETURN_SHALLOW_COPY
GStrV* ptr;
for (ptr = networks; *ptr; ptr++) {
*ptr = g_strdup(*ptr);
}
#else
networks = g_strdupv(networks);
#endif
g_strfreev(priv->networks);
self->networks = priv->networks = networks;
priv->pending_signals |= SIGNAL_BIT(NETWORKS);
}
#if STRV_GETTERS_RETURN_SHALLOW_COPY
else {
g_free(networks);
}
#endif
}

static
Expand Down

0 comments on commit dcf430e

Please sign in to comment.