After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 770335 - gdbus-codegen: generated getter for 'ao' property is actually (transfer container)
gdbus-codegen: generated getter for 'ao' property is actually (transfer conta...
Status: RESOLVED FIXED
Product: glib
Classification: Platform
Component: gdbus
unspecified
Other Linux
: Normal normal
: ---
Assigned To: gtkdev
gtkdev
Depends on:
Blocks:
 
 
Reported: 2016-08-24 13:58 UTC by Guillaume Desmottes
Modified: 2018-02-06 16:00 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
codegen: Fix a typo in g_variant_get_objv() (1.75 KB, patch)
2018-01-17 16:23 UTC, Philip Withnall
committed Details | Review

Description Guillaume Desmottes 2016-08-24 13:58:38 UTC
In ./gio/tests/gdbus-test-codegen-generated.c we have:

/**
 * foo_igen_bar_get_ao: (skip)
 * @object: A #FooiGenBar.
 *
 * (...)
 *
 * Returns: (transfer none): The property value or %NULL if the property is not set. Do not free the returned value, it belongs to @object.
 */
const gchar *const *
foo_igen_bar_get_ao (FooiGenBar *object)
{
  return FOO_IGEN_BAR_GET_IFACE (object)->get_ao (object);
}

which is implemented in proxy using:

static const gchar *const *
foo_igen_bar_proxy_get_ao (FooiGenBar *object)
{
  FooiGenBarProxy *proxy = FOO_IGEN_BAR_PROXY (object);
  GVariant *variant;
  const gchar *const *value = NULL;
  variant = g_dbus_proxy_get_cached_property (G_DBUS_PROXY (proxy), "ao");
  if (variant != NULL)
    {
      value = g_variant_get_objv (variant, NULL);
      g_variant_unref (variant);
    }
  return value;
}

But g_variant_get_objv() is actually (transfer container), and so is foo_igen_bar_get_ao(). This leaks to array leaks in the code using this generated API.
Comment 1 Philip Withnall 2018-01-17 16:23:37 UTC
Created attachment 366952 [details] [review]
codegen: Fix a typo in g_variant_get_objv()

g_variant_get_objpathv() doesn’t exist. The code actually meant
g_variant_get_objv().

This fixes a leak with `ao`-type properties in generated code.
Previously they wouldn’t be freed; now the container is (correctly)
freed.

Signed-off-by: Philip Withnall <withnall@endlessm.com>
Comment 2 Philip Withnall 2018-01-17 16:24:10 UTC
Fixed. Review welcome. Newly generated code:

static const gchar *const *
foo_igen_bar_proxy_get_ao (FooiGenBar *object)
{
  FooiGenBarProxy *proxy = FOO_IGEN_BAR_PROXY (object);
  GVariant *variant;
  const gchar *const *value = NULL;
  value = g_datalist_get_data (&proxy->priv->qdata, "ao");
  if (value != NULL)
    return value;
  variant = g_dbus_proxy_get_cached_property (G_DBUS_PROXY (proxy), "ao");
  if (variant != NULL)
    {
      value = g_variant_get_objv (variant, NULL);
      g_datalist_set_data_full (&proxy->priv->qdata, "ao", (gpointer) value, g_free);
      g_variant_unref (variant);
    }
  return value;
}
Comment 3 Emmanuele Bassi (:ebassi) 2018-02-06 15:56:57 UTC
Review of attachment 366952 [details] [review]:

:thumbsup:
Comment 4 Philip Withnall 2018-02-06 16:00:35 UTC
Pushed to master, thanks.

Attachment 366952 [details] pushed as 567e554 - codegen: Fix a typo in g_variant_get_objv()