Using GDBus I need to add an extra g_object_ref() (memory bug in glib?)

Hi all:

I’m using gdbus_codegen to generate bindings for a DBus server. The point is that I followed the examples I found (mainly in the official documentation) and I think that I found a memory bug. I have this piece of code:

static void
dbus_handle_method (MyObject *skeleton,
                    GDBusMethodInvocation *invocation,
                    gchar *fileName,
                    gchar *lockFilePath,
                    GVariantIter *extraParams,
                    gpointer data) {

    handle_application_is_being_refreshed(fileName, lockFilePath, extraParams, data);
    my_object_complete_method(skeleton, invocation);
}

With this code, valgrind shows an access-after-free bug, triggered after this function call has ended; but changing the last line into

my_object_complete_method(skeleton, g_object_ref(invocation));

seems to fix it, because Valgrind shows no error and no extra leaks when the program exists, no matter how many times I called the method.

So… is this a bug in GDBus, in the documentation, or am I doing something wrong?

Thanks.

Ok, as expected, the bug was mine :slight_smile:

The handler function must return TRUE to notify that it has managed the signal. In my example, it returned “void”, and that was interpreted as FALSE.

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.