libnm: add warning for bindings about broken functions for transferred GPtrArray

In commit 201c153e25 ('libnm: fix GObject Introspection annotations
for functions returning a GPtrArray') these annotations were changed
to fix Vala bindings. However, bindings may treat the transfer
annotation for GPtrArray differently, so depending on the binding
we either get a leak or a double free.

It's unclear how to fix that. For now, just add a warning to the
documentation to avoid it.

The following reproducer leads to a crash:

    #!/bin/python

    import gi

    gi.require_version("NM", "1.0")
    from gi.repository import NM

    def _pr(msg):
        NM.utils_print(0, msg + "\n")

    def process(nmc):
        for device in nmc.get_devices():
            cons = device.filter_connections(nmc.get_connections())
            _pr(
                "device %s (%s) has %s compatible connections"
                % (device.get_iface(), NM.Object.get_path(device), len(cons))
            )

    process(NM.Client.new())

See-also: https://gitlab.gnome.org/GNOME/gobject-introspection/-/issues/305
This commit is contained in:
Thomas Haller 2020-12-09 17:09:10 +01:00
parent d0a4661b65
commit b012877445
No known key found for this signature in database
GPG key ID: 29C2366E4DFC5728
2 changed files with 8 additions and 0 deletions

View file

@ -363,6 +363,10 @@ nm_access_point_connection_valid(NMAccessPoint *ap, NMConnection *connection)
* Returns: (transfer full) (element-type NMConnection): an array of
* #NMConnections that could be activated with the given @ap. The array should
* be freed with g_ptr_array_unref() when it is no longer required.
*
* WARNING: the transfer annotation for this function may not work correctly
* with bindings. See https://gitlab.gnome.org/GNOME/gobject-introspection/-/issues/305.
* You can filter the list yourself with nm_access_point_connection_valid().
**/
GPtrArray *
nm_access_point_filter_connections(NMAccessPoint *ap, const GPtrArray *connections)

View file

@ -2814,6 +2814,10 @@ nm_device_connection_compatible(NMDevice *device, NMConnection *connection, GErr
* Returns: (transfer full) (element-type NMConnection): an array of
* #NMConnections that could be activated with the given @device. The array
* should be freed with g_ptr_array_unref() when it is no longer required.
*
* WARNING: the transfer annotation for this function may not work correctly
* with bindings. See https://gitlab.gnome.org/GNOME/gobject-introspection/-/issues/305.
* You can filter the list yourself with nm_device_connection_valid().
**/
GPtrArray *
nm_device_filter_connections(NMDevice *device, const GPtrArray *connections)