Please take our Survey
logo       

Choosing A Webhost:
A web hosting service is a type of Internet hosting service that allows individuals and organizations to provide their own website accessible via the World Wide Web. Web hosts are companies that provide space on a server they own for use by their clients as well as providing Internet connectivity, typically in a data center. Web hosts can also provide data center space and connectivity to the Internet for servers they do not own to be located in their data center, called colocation. more...

[patch] dbus_connection_send_with_reply() leaking DBusPendingCalls: msg#00034

freedesktop.dbus

Subject: [patch] dbus_connection_send_with_reply() leaking DBusPendingCalls

Hi all.

I have implemented a small test server/client using the pending call system for getting replies. Then I valgrinded it and it seemed to have some odd memory leaks so I started digging.

It seems that the DBusPendingCall -struct isn't initialized properly in dbus_connection_send_with_reply(). It is first allocated using _dbus_pending_call_new (refcount=1). Then it is attached to the onnection using _dbus_connection_attach_pending_call_unlocked() which increases the refcount to 2. And finally if the DBusPendingCall is returned to caller the refcount is yet increased (to 3).

When the pending call is removed it's refcount is only decreased by one in free_pending_call_on_hash_removal(). Plus the caller should unref once if it received the pointer. So the DBusPendingCalls allocated in dbus_connection_send_with_reply() doesn't get freed.

See attached patch pending_call_fix.diff.


I've also been using dbus-send and noticed it lacks support to send boolean arguments. It was also a bit weird that --print-reply doesn't set the message type to method call since you propably won't otherwise get any reply. A small patch for those is as follows:

See attached patch dbus_send.diff.


Cheers,
Timo
diff -u -r1.75 dbus-connection.c
--- dbus/dbus-connection.c 2 Dec 2003 10:44:21 -0000 1.75
+++ dbus/dbus-connection.c 15 Feb 2004 16:08:45 -0000
@@ -1787,10 +1787,9 @@
}

if (pending_return)
- {
- dbus_pending_call_ref (pending);
- *pending_return = pending;
- }
+ *pending_return = pending;
+ else
+ dbus_pending_call_unref (pending);

CONNECTION_UNLOCK (connection);
diff -u -r1.7 dbus-send.c
--- tools/dbus-send.c 10 Oct 2003 02:42:21 -0000 1.7
+++ tools/dbus-send.c 15 Feb 2004 16:08:48 -0000
@@ -64,7 +64,7 @@
else if (strcmp (arg, "--session") == 0)
type = DBUS_BUS_SESSION;
else if (strcmp (arg, "--print-reply") == 0)
- print_reply = TRUE;
+ print_reply = TRUE, message_type = DBUS_MESSAGE_TYPE_METHOD_CALL;
else if (strstr (arg, "--dest=") == arg)
dest = strchr (arg, '=') + 1;
else if (strstr (arg, "--type=") == arg)
@@ -227,6 +227,18 @@
dbus_message_iter_append_string (&iter, c);
break;

+ case DBUS_TYPE_BOOLEAN:
+ if (strcasecmp(c, "true") == 0)
+ dbus_message_iter_append_boolean (&iter, TRUE);
+ else if (strcasecmp(c, "false") == 0)
+ dbus_message_iter_append_boolean (&iter, FALSE);
+ else
+ {
+ fprintf (stderr, "%s: Expected \"true\" or \"false\" instead of
\"%s\"\n", argv[0], c);
+ exit (1);
+ }
+ break;
+
default:
fprintf (stderr, "%s: Unsupported data type\n", argv[0]);
exit (1);
<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

Free Magazines

Cisco News
Receive a free quarterly e-newsletter with exclusive articles on how Cisco IT uses its own products and solutions to enable the business.
subscribe

Systems Management News, the newspaper for IT systems administration and data center managers! Each issue of Systems Management News is chock-full of news and analysis to help you understand what's happening in your field.
subscribe

The Enterprise Newsweekly eWeek is the essential technology information source for builders of e-business.
subscribe

Oracle Magazine Oracle Magazine contains technology strategy articles, sample code, tips, Oracle and partner news, how to articles for developers and DBAs, and more. Oracle (NASDAQ: ORCL) is the world's largest enterprise software company.
subscribe

Total Telecom Total Telecom is "The Economist of the communications industry".
subscribe

Navigation

Home | advertise | OSDir is an inevitable website. super tiny logo