From 233ec0f562e12adfbe1ca5182bebd22c19c31ea4 Mon Sep 17 00:00:00 2001 From: Mike Gorse Date: Thu, 27 Dec 2012 16:50:04 -0500 Subject: Fix some ref count issues Add refs in some places where they were previously not present, and be more thorough about removing refs when disposing. This should fix some leaks, though it is likely that many still remain. Also add a test program that can be used to test for some leaks. --- test/Makefile.am | 5 ++++ test/memory.c | 78 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 83 insertions(+) create mode 100644 test/Makefile.am create mode 100644 test/memory.c (limited to 'test') diff --git a/test/Makefile.am b/test/Makefile.am new file mode 100644 index 00000000..ab47b948 --- /dev/null +++ b/test/Makefile.am @@ -0,0 +1,5 @@ +LDADD = $(top_builddir)/atspi/libatspi.la +noinst_PROGRAMS = memory +memory_SOURCES = memory.c +memory_CFLAGS = $(GLIB_CFLAGS) $(DBUS_CFLAGS) +memory_LDFLAGS = diff --git a/test/memory.c b/test/memory.c new file mode 100644 index 00000000..28c3a8ec --- /dev/null +++ b/test/memory.c @@ -0,0 +1,78 @@ +#include "atspi/atspi.h" +#include +#include +#include + +pid_t child_pid; +AtspiEventListener *listener; + +void +basic (AtspiAccessible *obj) +{ + gchar *str; + gint count; + gint i; + AtspiAccessible *accessible; + GError *error = NULL; + + str = atspi_accessible_get_name (obj, &error); + if (str) + g_free (str); + accessible = atspi_accessible_get_parent (obj, NULL); + if (accessible) + g_object_unref (accessible); + count = atspi_accessible_get_child_count (obj, &error); + for (i = 0; i < count; i++) + { + accessible = atspi_accessible_get_child_at_index (obj, i, &error); + if (accessible) + g_object_unref (accessible); + } +} + +static gboolean +end (void *data) +{ + atspi_event_quit (); + atspi_exit (); + exit (0); +} + +static gboolean +kill_child (void *data) +{ + kill (child_pid, SIGTERM); + return FALSE; +} + +void +on_event (AtspiEvent *event, void *data) +{ + if (atspi_accessible_get_role (event->source, NULL) == ATSPI_ROLE_DESKTOP_FRAME) + { + if (strstr (event->type, "add")) + { + AtspiAccessible *desktop = atspi_get_desktop (0); + basic (desktop); + g_object_unref (desktop); + g_timeout_add (3000, kill_child, NULL); + } + else + { + g_idle_add (end, NULL); + } + } + g_boxed_free (ATSPI_TYPE_EVENT, event); +} + +main() +{ + atspi_init (); + + listener = atspi_event_listener_new (on_event, NULL, NULL); + atspi_event_listener_register (listener, "object:children-changed", NULL); + child_pid = fork (); + if (!child_pid) + execlp ("gedit", "gedit", NULL); + atspi_event_main (); +} -- cgit v1.2.1