Daemon using dbus to send messages seems to use lots of memory without release them.
Croach
croach at gmail.com
Mon Dec 24 23:21:19 PST 2012
2012/12/25 Croach <croach at gmail.com>:
> Hi,
>
> I have do porting dbus-1.6.4 to a embedded system, and I find that the
> memory of the daemon using dbus grows till the daemon runs out of the
> memory.
> I have put the following sample program to a function and run it for
> 10000 times with Valgrind.
>
> http://dbus.freedesktop.org/doc/dbus-tutorial.html#sample-program-1
I have updated the program we tested with Valgrind.
We use glib-2.28.8, dbus-glib-0.100.
#include <dbus/dbus.h>
#include <dbus/dbus-glib.h>
#include <stdlib.h>
int test()
{
DBusGConnection *connection;
GError *error;
DBusGProxy *proxy;
char **name_list;
char **name_list_ptr;
g_type_init ();
error = NULL;
connection = dbus_g_bus_get (DBUS_BUS_SESSION, &error);
if (connection == NULL)
{
g_printerr ("Failed to open connection to bus: %s\n", error->message);
g_error_free (error);
exit (1);
}
/* Create a proxy object for the "bus driver" (name "org.freedesktop.DBus") */
proxy = dbus_g_proxy_new_for_name (connection,
DBUS_SERVICE_DBUS,
DBUS_PATH_DBUS,
DBUS_INTERFACE_DBUS);
/* Call ListNames method, wait for reply */
error = NULL;
if (!dbus_g_proxy_call (proxy, "ListNames", &error, G_TYPE_INVALID,
G_TYPE_STRV, &name_list, G_TYPE_INVALID))
{
/* Just do demonstrate remote exceptions versus regular GError */
if (error->domain == DBUS_GERROR && error->code ==
DBUS_GERROR_REMOTE_EXCEPTION)
g_printerr ("Caught remote method exception %s: %s",
dbus_g_error_get_name (error),
error->message);
else
g_printerr ("Error: %s\n", error->message);
g_error_free (error);
exit (1);
}
/* Print the results */
g_print ("Names on the message bus:\n");
for (name_list_ptr = name_list; *name_list_ptr; name_list_ptr++)
{
g_print (" %s\n", *name_list_ptr);
}
g_strfreev (name_list);
g_type_class_ref(proxy);
g_object_unref (proxy);
proxy = NULL;
name_list = NULL;
return 0;
}
int main()
{
int count = 10000;
while (count -- > 0) {
test();
}
}
>
> The memory grows up and valgrind reports that "still reachable" with some bytes.
> I know that the meaning of "still reachable" is not memory leak, but
> the program uses lots of memory.
> So I would like to know what have I missed anything about running the
> sample program or should I use any function to release the memory
> after using g_object_unref()?
>
> Thanks for any help.
> Croach Chang
More information about the dbus
mailing list