From: JunsuChoi Date: Tue, 4 Apr 2017 01:45:24 +0000 (+0900) Subject: Fix memory leak X-Git-Tag: accepted/tizen/unified/20170419.163242^0 X-Git-Url: http://review.tizen.org/git/?p=platform%2Fupstream%2Fat-spi2-core.git;a=commitdiff_plain;h=576781b36f2d342e20acdf750b7b19d3ff9c6628 Fix memory leak bus/at-spi-bus-launcher.c argv[1] is allocated in memory by g_strdup_printf. but do not free. So I add g_free function. test/at_spi2_tool.c Added a null check to avoid double free. Change-Id: I80ce6af2839c4dfe9c1460885f5b93f281f7ef29 --- diff --git a/bus/at-spi-bus-launcher.c b/bus/at-spi-bus-launcher.c index 3f6c917..db1db5c 100644 --- a/bus/at-spi-bus-launcher.c +++ b/bus/at-spi-bus-launcher.c @@ -1,6 +1,6 @@ /* -*- mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*- - * - * at-spi-bus-launcher: Manage the a11y bus as a child process + * + * at-spi-bus-launcher: Manage the a11y bus as a child process * * Copyright 2011 Red Hat, Inc. * @@ -124,7 +124,7 @@ setup_bus_child (gpointer data) #ifdef __linux #include prctl (PR_SET_PDEATHSIG, 15); -#endif +#endif } /** @@ -156,7 +156,7 @@ on_bus_exited (GPid pid, gpointer data) { A11yBusLauncher *app = data; - + app->a11y_bus_pid = -1; app->state = A11Y_BUS_STATE_ERROR; if (app->a11y_launch_error_message == NULL) @@ -169,7 +169,7 @@ on_bus_exited (GPid pid, app->a11y_launch_error_message = g_strdup_printf ("Bus stopped by signal %d", WSTOPSIG (status)); } g_main_loop_quit (app->loop); -} +} static gboolean ensure_a11y_bus (A11yBusLauncher *app) @@ -181,12 +181,12 @@ ensure_a11y_bus (A11yBusLauncher *app) if (app->a11y_bus_pid != 0) return FALSE; - + argv[1] = g_strdup_printf ("--config-file=%s/at-spi2/accessibility.conf", SYSCONFDIR); if (pipe (app->pipefd) < 0) g_error ("Failed to create pipe: %s", strerror (errno)); - + if (!g_spawn_async (NULL, argv, NULL, @@ -241,9 +241,12 @@ ensure_a11y_bus (A11yBusLauncher *app) } #endif + if (argv[1]) g_free(argv[1]); + return TRUE; - + error: + if (argv[1]) g_free(argv[1]); close (app->pipefd[0]); close (app->pipefd[1]); app->state = A11Y_BUS_STATE_ERROR; @@ -379,7 +382,7 @@ handle_set_property (GDBusConnection *connection, A11yBusLauncher *app = user_data; const gchar *type = g_variant_get_type_string (value); gboolean enabled; - + if (g_strcmp0 (type, "b") != 0) { g_set_error (error, G_DBUS_ERROR, G_DBUS_ERROR_INVALID_ARGS, @@ -429,7 +432,7 @@ on_bus_acquired (GDBusConnection *connection, A11yBusLauncher *app = user_data; GError *error; guint registration_id; - + if (connection == NULL) { g_main_loop_quit (app->loop); @@ -506,7 +509,7 @@ on_sigterm_pipe (GIOChannel *channel, gpointer data) { A11yBusLauncher *app = data; - + g_main_loop_quit (app->loop); return FALSE; @@ -544,7 +547,7 @@ already_running () bridge_display = XOpenDisplay (NULL); if (!bridge_display) return FALSE; - + AT_SPI_BUS = XInternAtom (bridge_display, "AT_SPI_BUS", False); XGetWindowProperty (bridge_display, XDefaultRootWindow (bridge_display), @@ -828,7 +831,7 @@ main (int argc, if (_global_app->a11y_bus_pid > 0) kill (_global_app->a11y_bus_pid, SIGTERM); - /* Clear the X property if our bus is gone; in the case where e.g. + /* Clear the X property if our bus is gone; in the case where e.g. * GDM is launching a login on an X server it was using before, * we don't want early login processes to pick up the stale address. */ diff --git a/test/at_spi2_tool.c b/test/at_spi2_tool.c index 2eae131..018acc7 100644 --- a/test/at_spi2_tool.c +++ b/test/at_spi2_tool.c @@ -240,12 +240,13 @@ static char *_get_states(AtspiAccessible *node, int length_limit) { AtspiStateSet *node_state_set = atspi_accessible_get_state_set(node); GArray *states = atspi_state_set_get_states(node_state_set); + if (!states) return NULL; g_array_sort(states, _int_sort_function); AtspiStateType state_type; char *state_string = NULL; - for (int i = 0; states && (i < states->len); i++) { + for (int i = 0; i < states->len; i++) { state_type = g_array_index(states, AtspiStateType, i); char node_state_str[8];