Bug 8832

Summary: Document that dbus_g_method_get_sender's return needs freeing
Product: dbus Reporter: frederic heem <frederic.heem>
Component: GLibAssignee: Rob Taylor <rob.taylor>
Status: RESOLVED FIXED QA Contact: John (J5) Palmieri <johnp>
Severity: normal    
Priority: high    
Version: unspecified   
Hardware: Other   
OS: Linux (All)   
Whiteboard:
i915 platform: i915 features:
Attachments: dbus_g_method_get_sender-return-const-char.txt

Description frederic heem 2006-10-30 06:32:57 UTC
dbus_g_method_get_sender duplicates memory given by dbus_message_get_sender
IMHO, it shouldn't duplicate anything, it should just returns a const gchar* 
returned by dbus_message_get_sender.
This reduced the risk of memory leak  from an application point of view. It is 
also faster.
Comment 1 frederic heem 2006-10-30 06:35:03 UTC
Created attachment 7588 [details] [review]
dbus_g_method_get_sender-return-const-char.txt
Comment 2 Rob Taylor 2006-12-12 05:24:36 UTC
No.
Comment 3 frederic heem 2006-12-12 05:27:11 UTC
Could you please explain why ?
Comment 4 Rob Taylor 2006-12-12 05:29:24 UTC
Because that memory is freed as soon as the message is discarded, it breaks api,
and breaks exitig code.
Comment 5 frederic heem 2006-12-12 05:44:15 UTC
Why dbus-glib imposes the burden of freeing the memory allocated by 
dbus-glib ? 
Anyway, an application must not use the free function of pointer allocated by 
a library. The library shall provide an API to free it itself.
Moreover, the memory is not freed when the message is discarded.
Comment 6 Rob Taylor 2006-12-12 05:54:14 UTC
There is nowhere that dbus-glib could free this sensibly. Its standard glib
practice in such cases that the client code frees the memory (using g_free).
The memory returned by dbus_message_get_sender is a pointer to the string within
the message itself. In the core bindings its fine for dbus_message_get_sender to
return const char* as the user is managing the message lifetime herself, but in
dbus-glib the user should never have to worry about message lifetime (or indeed
messages) so hence the string duplication.
Comment 7 frederic heem 2006-12-12 05:59:13 UTC
Fine, but please document the function that the returned pointer has to be 
freed with g_free.
Comment 8 Rob Taylor 2006-12-12 06:04:53 UTC
Agreed, renamed and reopened bug appropriately
Comment 9 Rob Taylor 2007-02-08 16:02:49 UTC
Fixed in git head.

Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct. How we collect and use information is described in our Privacy Policy.