Question

I'm new to C language

I use dbus_g_bus_get() to connect the Session Management signals:

static DBusGProxy * connect_to_session (void) 
{
    DBusGConnection *connection;
    DBusGProxy *proxy;
    GError *error = NULL;

    connection = dbus_g_bus_get (DBUS_BUS_SYSTEM, &error); /* line 1472 */

    if (error) {
        g_warning ("Couldn't connect to system bus: %s", error->message);
        g_error_free(error);
        return NULL;
    }
    /* Get the current session object */
    proxy = dbus_g_proxy_new_for_name (connection,
                                       "org.gnome.SessionManager",
                                       "/org/gnome/SessionManager",
                                       "org.gnome.SessionManager");

    if (!proxy) {
        g_warning ("Unable to get the SessionManager.");
        dbus_g_connection_unref (connection);
        return NULL;
    }

    dbus_g_proxy_add_signal (proxy, "SessionOver", G_TYPE_INVALID, G_TYPE_INVALID);
    dbus_g_proxy_connect_signal (proxy, "SessionOver", G_CALLBACK (session_die_cb), NULL, NULL);

    g_object_set_data (G_OBJECT (proxy), "connection", connection);
    return proxy;
}

call this in main:

int main(int argc, char* argv[])
{
    --------------------------------------------
    /* Connect the Session Management signals */
    proxy = connect_to_session ();

    if (proxy) {
        DBusGConnection *conn;
        conn = (DBusGConnection *)g_object_get_data (G_OBJECT (proxy), "connection");
        if (conn)
            dbus_g_connection_unref (conn);

        g_object_unref (proxy);
    }

    return 0;
}

and valgrind output this:

32 bytes in 1 blocks are possibly lost in loss record 5,342 of 13,110
    at 0x4C2C6AE: realloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
    by 0x6F2ABEE: g_realloc (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.3703.0)
    by 0x6CBC577: g_type_set_qdata (in /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0.3703.0)
    by 0x513A3D4: ??? (in /usr/lib/x86_64-linux-gnu/libdbus-glib-1.so.2.2.2)
    by 0x512F48C: dbus_g_bus_get (in /usr/lib/x86_64-linux-gnu/libdbus-glib-1.so.2.2.2)
    by 0x40B669: main (gui.c:1472)

I don't know if this report it is false or not.

Thanks

Was it helpful?

Solution

Valgrind has some issues dealing with glbal variables, there is a lot of posts hese at Stackoverflow. You are calling dbus_g_bus_get, and the return is a poiner to a global variable.

DBusGConnection* dbus_g_bus_get (DBusBusType type, GError **error);

Returns a connection to the given bus. The connection is a global variable shared with other callers of this function. 

You could also try calling dbus_g_connection_ref after you get the connection.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top