0
votes

I'm trying to call DBus method of NetworkManager by using Glib-Dbus in linux. When I create a GDBusProxy by g_dbus_proxy_new_sync and then free it by g_object_unref, the new created GDBusProxy seems not to be freed. I have used pmap -x <pid> to display memory usage of my process and the RSS value increased continuously. Can someone help me?

Here is the code that causes the problem:


    int main (int argc, char *argv[])
    {
        GDBusConnection * connection = NULL;
        GDBusProxy * proxy = NULL;
        GError * error = NULL;

        connection = g_bus_get_sync(G_BUS_TYPE_SYSTEM,
                                    NULL,
                                    &error);
        g_assert_no_error(error);
        error = NULL;

        while (1)
        {
            proxy = g_dbus_proxy_new_sync(connection,
                                          G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES |      G_DBUS_PROXY_FLAGS_DO_NOT_CONNECT_SIGNALS,
                                          NULL,
                                          "org.freedesktop.NetworkManager",
                                          "/org/freedesktop/NetworkManager/Settings",
                                          "org.freedesktop    .NetworkManager.Settings",
                                          NULL,
                                          NULL);

            g_assert(proxy != NULL);
            g_object_unref(proxy);

        }

        g_object_unref(connection);

        return 0;
    }

Thanks in advance

3

3 Answers

2
votes

GLib and associated libraries do not use the system malloc/free pair; they usually resort to an internal slab allocator. This means that just reading the output of top or pmap is not in any way useful to determine whether GLib, or any application using GLib, is actually leaking:

You should use Valgrind, instead, and make sure to read this wiki page for some of the details on how to use Valgrind with applications using GLib.

1
votes

You can use Valgrind to find out the memory leak in your program.

0
votes

There is a patch attached to this bug report (which has been applied to the glib git repository) which should solve your problem: https://bugzilla.gnome.org/show_bug.cgi?id=758641

Presumably it will be in glib-2.46.3 and/or glib-2.48. It seems just to have been merged in the glib-2.46 branch.