diff options
author | William Jon McCann <jmccann@redhat.com> | 2012-09-14 12:50:18 -0400 |
---|---|---|
committer | Mike Gorse <mgorse@suse.com> | 2012-09-17 20:26:10 -0500 |
commit | 8368296824454486926c33e1f1e28612ce90d726 (patch) | |
tree | 2110b5b2931535252fca1e6892a145e9bac092b4 | |
parent | 3c21b42d31fd19c28bca9417c66bbd5c9fa4c6f8 (diff) | |
download | at-spi2-core-8368296824454486926c33e1f1e28612ce90d726.tar.gz |
Don't leak dbus connections
By using a private connection and closing it.
https://bugzilla.gnome.org/show_bug.cgi?id=684033
-rw-r--r-- | atspi/atspi-misc.c | 49 | ||||
-rw-r--r-- | registryd/registry-main.c | 6 |
2 files changed, 49 insertions, 6 deletions
diff --git a/atspi/atspi-misc.c b/atspi/atspi-misc.c index fa7ca643..f45cd76e 100644 --- a/atspi/atspi-misc.c +++ b/atspi/atspi-misc.c @@ -135,6 +135,13 @@ cleanup () { g_hash_table_destroy (refs); } + + if (bus) + { + dbus_connection_close (bus); + dbus_connection_unref (bus); + bus = NULL; + } } static gboolean atspi_inited = FALSE; @@ -156,12 +163,16 @@ handle_get_bus_address (DBusPendingCall *pending, void *user_data) DBUS_TYPE_INVALID)) { DBusError error; + DBusConnection *bus; + dbus_error_init (&error); - DBusConnection *bus = dbus_connection_open (address, &error); + bus = dbus_connection_open_private (address, &error); if (bus) { if (app->bus) - dbus_connection_unref (app->bus); + { + dbus_connection_unref (app->bus); + } app->bus = bus; } else @@ -1433,6 +1444,19 @@ get_accessibility_bus_address_dbus (void) return address; } +static DBusConnection *a11y_bus; +static dbus_int32_t a11y_dbus_slot = -1; + +static void +a11y_bus_free (void *data) +{ + if (data == a11y_bus) + { + a11y_bus = NULL; + dbus_connection_free_data_slot (&a11y_dbus_slot); + } +} + DBusConnection * atspi_get_a11y_bus (void) { @@ -1440,6 +1464,13 @@ atspi_get_a11y_bus (void) DBusError error; char *address; + if (a11y_bus && dbus_connection_get_is_connected (a11y_bus)) + return a11y_bus; + + if (a11y_dbus_slot == -1) + if (!dbus_connection_allocate_data_slot (&a11y_dbus_slot)) + g_warning ("at-spi: Unable to allocate D-Bus slot"); + address = get_accessibility_bus_address_x11 (); if (!address) address = get_accessibility_bus_address_dbus (); @@ -1447,10 +1478,10 @@ atspi_get_a11y_bus (void) return NULL; dbus_error_init (&error); - bus = dbus_connection_open (address, &error); + a11y_bus = dbus_connection_open_private (address, &error); g_free (address); - if (!bus) + if (!a11y_bus) { g_warning ("Couldn't connect to accessibility bus: %s", error.message); dbus_error_free (&error); @@ -1458,15 +1489,21 @@ atspi_get_a11y_bus (void) } else { - if (!dbus_bus_register (bus, &error)) + if (!dbus_bus_register (a11y_bus, &error)) { g_warning ("Couldn't register with accessibility bus: %s", error.message); dbus_error_free (&error); + dbus_connection_close (a11y_bus); + dbus_connection_unref (a11y_bus); + a11y_bus = NULL; return NULL; } } - return bus; + /* Simulate a weak ref on the bus */ + dbus_connection_set_data (a11y_bus, a11y_dbus_slot, a11y_bus, a11y_bus_free); + + return a11y_bus; } /** diff --git a/registryd/registry-main.c b/registryd/registry-main.c index 2ba9f4ce..b088b1ae 100644 --- a/registryd/registry-main.c +++ b/registryd/registry-main.c @@ -246,5 +246,11 @@ main (int argc, char **argv) } g_main_loop_run (mainloop); + + dbus_connection_close (bus); + dbus_connection_unref (bus); + g_object_unref (dec); + g_object_unref (registry); + return 0; } |