org.freedesktop.DBus.GLib.ReturnVal frees returns value

Havoc Pennington hp at redhat.com
Fri Sep 15 09:41:21 PDT 2006


frederic heem wrote:
> 
> sniffer_get allocates the string, stores it as the key value in a hash table 
> and return the pointer to the string. Valgrind found that dbus is freeing the 
> return value ?  
> Dbus must not free memory an application has allocated because there could be 
> a mismatch malloc/free between the application and libdbus. 
> 

If the return value were not freed, then the application would always 
have to keep it around indefinitely, even if it was some on-the-fly 
created string with no reason to store it.

If it's copied, then there's an abstraction barrier where the app is 
welcome to store it or create it on the fly. This is the standard 
glib/gtk API convention used in most of glib/gtk unless the returned 
string is in some way inherently already stored.

Just add a g_strdup().

Havoc


More information about the dbus mailing list