Bug 8832 - Document that dbus_g_method_get_sender's return needs freeing
Summary: Document that dbus_g_method_get_sender's return needs freeing
Status: RESOLVED FIXED
Alias: None
Product: dbus
Classification: Unclassified
Component: GLib (show other bugs)
Version: unspecified
Hardware: Other Linux (All)
: high normal
Assignee: Rob Taylor
QA Contact: John (J5) Palmieri
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-10-30 06:32 UTC by frederic heem
Modified: 2007-02-08 16:02 UTC (History)
0 users

See Also:
i915 platform:
i915 features:


Attachments
dbus_g_method_get_sender-return-const-char.txt (1.48 KB, patch)
2006-10-30 06:35 UTC, frederic heem
Details | Splinter Review

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.