My problem centers mostly around GVariants.
For example, the DBusSignalCallback:
void
(* GDBusSignalCallback) (
GDBusConnection* connection,
const gchar* sender_name,
const gchar* object_path,
const gchar* interface_name,
const gchar* signal_name,
GVariant* parameters,
gpointer user_data
)
The connection needs to survive in my case after the callback. user_data was created by me, so I know how to handle it.
Do I assume the rest of the parameters do not need to be freed by g_free, or g_variant_unref?
And when I decode GVariant, how do I know which pointers that are loaded need to be freed, and which do not?
I have seen errors generated deep in the library when some free function was called on something that couldn’t be freed.
Decode of GVariant parameters:
g_variant_get(parameters, "(&sa{sv}as)", &interface_name, &properties, &unknown);
So interface_name is byte array, which could have g_free() called on it, properties is a GVariantIter which could also be freed with g_variant_iter_free (but the doc suggests not to do it unless allocated by g_variant_iter_new() or g_variant_iter_copy(), but who knows what g_variant_get() actually does), and unknown is also a byte array.
Then you have a loop acquiring items from the properties dictionary:
while(g_variant_iter_next(properties, “{&sv}”, &key, &value)) {
So you have a char or byte array key, and a variant value. These could possibly be freed by g_free and g_variant_unref(). And if the variant has a byte array, that also could be freed by g_free().
I tried to run valgrind on my program, and it seemed to suggest that g_variant_get causes memory leaks. But I have no idea if valgrind is valid when linked into libg/libgio.
Does libgio/libg have anything for analyzing memory, and preventing memory leaks, or maybe double frees or frees of storage that cannot be freed?