Fix memory leak 58/245858/2 submit/tizen/20201018.221456
authorBartlomiej Grzelewski <b.grzelewski@samsung.com>
Mon, 5 Oct 2020 12:34:48 +0000 (14:34 +0200)
committerBartlomiej Grzelewski <b.grzelewski@samsung.com>
Fri, 16 Oct 2020 13:42:33 +0000 (15:42 +0200)
* Memory allocated by atspi event must be manually freed.
* g_object_unref objects returned by _directional_depth_first_search.
* Remove memory leak in navigator.c
* Remove component leaks.
* Remove memory leak in _focus_widget
* Fix memory leak and memory corruption in app_tracker.c.
* Remove memory leak from screen reader spi module.
* AtspiDevice events must be free with g_boxed_free.
* Free atspi relation set.
* Free memory allocated by atspi_accessible_get_component_iface.
* Remove leak in flat_navic.
* Remove memory leaks from smart notification module.
* Remove memory leaks from spi module.

Change-Id: I76e3c18f2b6bb1d1d6008c68a8b32587779a8f50

include/flat_navi.h
src/app_tracker.c
src/flat_navi.c
src/keyboard_tracker.c
src/navigator.c
src/screen_reader_spi.c
src/screen_reader_system.c
src/smart_notification.c
src/window_tracker.c

index ba8d1441f5aae1e31b4d0b593dcb71ed2b96d422..f303629ef9a0f4cdcc5d9dba95ca2d8ded2e1a8f 100644 (file)
@@ -159,7 +159,8 @@ Eina_Bool flat_navi_context_current_set(FlatNaviContext *ctx, AtspiAccessible *t
  * @param ctx FlatNaviContext
  * @param x_cord gint X coordinate
  * @param y_cord gint Y coordinate
- * @param obj AtspiAccessible Reference to object on point
+ * @param obj AtspiAccessible Reference to object on point.
+ *            Caller is responsible for free this object with g_object_unref.
  *
  * @return Eina_Bool true on success
  *
@@ -172,24 +173,26 @@ Eina_Bool flat_navi_context_current_at_x_y_set(FlatNaviContext *ctx, gint x_cord
  *
  * @param ctx FlatNaviContext
  *
- * @return Ownership of the first object in context
+ * @return Ownership of the first object in context.
+ *         Caller is responsible for free this object with g_object_unref.
  *
  * @see flat_navi_context_first()
  * @see flat_navi_context_free()
  */
-const AtspiAccessible *flat_navi_context_first_get(FlatNaviContext *ctx);
+AtspiAccessible *flat_navi_context_first_get(FlatNaviContext *ctx);
 
 /**
  * @brief Returns the last item in context;
  *
  * @param ctx FlatNaviContext
  *
- * @return Ownership of the last object in context
+ * @return Ownership of the last object in context.
+ *         Caller is responsible for free this object with g_object_unref.
  *
  * @see flat_navi_context_last()
  * @see flat_navi_context_free()
  */
-const AtspiAccessible *flat_navi_context_last_get(FlatNaviContext *ctx);
+AtspiAccessible *flat_navi_context_last_get(FlatNaviContext *ctx);
 
 typedef enum {
        FLAT_NAVI_CONTEXT_VALID, // context is valid
index 09fe770f0cfdbeac6c466752ce20b72c0b52922c..1912653857eaa029c936eb27871fc354c577c8a9 100644 (file)
@@ -76,28 +76,21 @@ static gboolean _on_timeout_rebuild_navigation_context(gpointer user_data)
        }
 
        if (atd->view_content_changed_ecd && atd->view_content_changed_ecd->func) {
-               AtspiRole role = ATSPI_ROLE_INVALID;
-               AtspiAccessibleDefaultLabelInfo *dli;
-
                Eina_Bool default_label_enabled = EINA_TRUE;
-               AtspiAccessible *root = atd->root;
-               GHashTable *attributes = NULL;
                gchar *attribute_default_label = NULL;
+               AtspiAccessibleDefaultLabelInfo *dli =
+                       atspi_accessible_get_default_label_info(atd->root, NULL);
 
-               dli =  atspi_accessible_get_default_label_info(atd->root, NULL);
                if (!dli) {
                        ERROR("Default label info is NULL!");
                        return FALSE;
                }
 
-               WindowActivateInfoType window_activate_info_type = window_tracker_window_activate_info_type_get(atd->window_tracker_data, root);
-
-               root = dli->obj;
-               role = dli->role;
-               attributes = dli->attributes;
+               WindowActivateInfoType window_activate_info_type =
+                       window_tracker_window_activate_info_type_get(atd->window_tracker_data, atd->root);
 
                if (window_activate_info_type & ACCESSIBLE_WINDOW_ACTIVATE_INFO_DEFAULT_LABEL_ENABLED_WITHOUT_WINDOW) {
-                       switch (role) {
+                       switch (dli->role) {
                        case ATSPI_ROLE_PAGE_TAB:
                        case ATSPI_ROLE_POPUP_MENU:
                        case ATSPI_ROLE_PANEL:
@@ -111,8 +104,8 @@ static gboolean _on_timeout_rebuild_navigation_context(gpointer user_data)
                        default_label_enabled = EINA_FALSE;
                }
 
-               if (attributes && (role != ATSPI_ROLE_WINDOW && role != ATSPI_ROLE_INPUT_METHOD_WINDOW)) {
-                       attribute_default_label = g_hash_table_lookup(attributes, "default_label");
+               if (dli->attributes && (dli->role != ATSPI_ROLE_WINDOW && dli->role != ATSPI_ROLE_INPUT_METHOD_WINDOW)) {
+                       attribute_default_label = g_hash_table_lookup(dli->attributes, "default_label");
                        if (attribute_default_label) {
                                if (!g_strcmp0(attribute_default_label, "disabled")) {
                                        default_label_enabled = EINA_FALSE;
@@ -125,14 +118,17 @@ static gboolean _on_timeout_rebuild_navigation_context(gpointer user_data)
                if (default_label_enabled)
                        tw_purge(EINA_TRUE);
 
-               gchar *id = atspi_accessible_get_unique_id(root, NULL);
-               DEBUG("Rebuilding navigation context - root: %s, role: %d, default_label_enabled : %s", id, role, default_label_enabled ? "true" : "false");
+               gchar *id = atspi_accessible_get_unique_id(dli->obj, NULL);
+               DEBUG("Rebuilding navigation context - root: %s, role: %d, default_label_enabled : %s", id, dli->role, default_label_enabled ? "true" : "false");
                g_free(id);
 
-               if (root)
-                       atd->view_content_changed_ecd->func(root, role, atd->view_content_changed_ecd->user_data, default_label_enabled);
+               if (dli->obj)
+                       atd->view_content_changed_ecd->func(dli->obj, dli->role, atd->view_content_changed_ecd->user_data, default_label_enabled);
+
                if (dli->attributes)
                        g_hash_table_unref(dli->attributes);
+               if (dli->obj)
+                       g_object_unref(dli->obj);
                g_free(dli);
        }
        atd->timer = 0;
@@ -188,11 +184,17 @@ static Eina_Bool _read_cb(void *data)
 {
        DEBUG("START");
        App_Tracker_Data *atd = (App_Tracker_Data*)data;
-       AtspiAccessible *current_obj = atd->read_timer_user_data;
+       AtspiAccessible *current_obj = g_object_ref(atd->read_timer_user_data);
+
        generate_what_to_read_and_speak(get_pointer_to_service_data_struct()->navigator_data, current_obj, EINA_TRUE);
        atd->read_timer = NULL;
+
+       g_object_unref(atd->read_timer_user_data);
        atd->read_timer_user_data = NULL; /* It's on to clean it as we cancel next call. */
+
        sound_n_vibration_feedback_generate(current_obj);
+       g_object_unref(current_obj);
+
        return ECORE_CALLBACK_CANCEL;
 }
 #endif
@@ -245,6 +247,7 @@ static void _object_needs_scroll_gesture_send(App_Tracker_Data *atd, AtspiAccess
        if (obj) {
                comp = atspi_accessible_get_component_iface(obj);
                rect = atspi_component_get_extents(comp, ATSPI_COORD_TYPE_SCREEN, NULL);
+               g_object_unref(comp);
                highlighted_object_x = rect->x + rect->width / 2;
                highlighted_object_y = rect->y + rect->height / 2;
                g_free(rect);
@@ -271,18 +274,18 @@ static void _on_atspi_event_cb(AtspiEvent *event, void *user_data)
 
        if (!event->source) {
                ERROR("empty event source");
-               return;
+               goto end;
        }
 
        if (!user_data) {
                ERROR("user_data could not be NULL");
-               return;
+               goto end;
        }
 
        App_Tracker_Data *atd = (App_Tracker_Data*)user_data;
        AtspiRole role = atspi_accessible_get_role(event->source, NULL);
        if (role == ATSPI_ROLE_DESKTOP_FRAME)
-               return;
+               goto end;
 
        gchar *id = atspi_accessible_get_unique_id(event->source, NULL);
        DEBUG("signal:%s, source: %s, role: %d, detail1:%i, detail2: %i", event->type, id, role, event->detail1, event->detail2);
@@ -291,13 +294,15 @@ static void _on_atspi_event_cb(AtspiEvent *event, void *user_data)
        if (!g_strcmp0(event->type, "object:state-changed:highlighted")) {
 #ifndef SCREEN_READER_TV
                if (event->detail1) {//Update highlight object only when grab is called
-                       new_highlighted_obj = event->source;
-                       if (atd->read_timer) {
+                       new_highlighted_obj = g_object_ref(event->source); /* new ref */
+
+                       if (atd->read_timer)
                                ecore_timer_del(atd->read_timer);
-                               atd->read_timer_user_data = NULL;
-                       }
 
+                       g_object_unref(atd->read_timer_user_data);
                        atd->read_timer_user_data = new_highlighted_obj;
+                       g_object_ref(atd->read_timer_user_data);
+
                        atd->read_timer = ecore_timer_add(HIGHLIGHT_UPDATE_READ_TIMEOUT, _read_cb, atd);
                        atd->prev_highlighted_obj = new_highlighted_obj;
                        /* send - scroll gesture required info */
@@ -310,6 +315,8 @@ static void _on_atspi_event_cb(AtspiEvent *event, void *user_data)
                                g_free(id);
                                ecore_timer_del(atd->read_timer);
                                atd->read_timer = NULL;
+
+                               g_object_unref(atd->read_timer_user_data);
                                atd->read_timer_user_data = NULL;
                        }
 
@@ -319,7 +326,7 @@ static void _on_atspi_event_cb(AtspiEvent *event, void *user_data)
                }
 #endif
        } else if (!g_strcmp0(event->type, "object:active-descendant-changed")) {
-               new_highlighted_obj = atspi_accessible_get_child_at_index(event->source, event->detail1, NULL);
+               new_highlighted_obj = atspi_accessible_get_child_at_index(event->source, event->detail1, NULL); /* new ref */
        } else if (!g_strcmp0("object:state-changed:showing", event->type)) {
                if (event->detail1) { /* Showing */
                        if (role == ATSPI_ROLE_WINDOW) {
@@ -340,7 +347,7 @@ static void _on_atspi_event_cb(AtspiEvent *event, void *user_data)
                                if (is_text_selection_mode) {
                                        /*TODO: this ignores toast popup providing cut, copy information.
                                        if other popup is showing then rebuild navigation context. */
-                                       return;
+                                       goto end;
                                }
                                if (window_tracker_subroot_get(atd->window_tracker_data)) {
                                        char *text_to_speak = NULL;
@@ -372,8 +379,7 @@ static void _on_atspi_event_cb(AtspiEvent *event, void *user_data)
                                timer_reschedule(atd);
                        }
                }
-       }
-       else if (!g_strcmp0(event->type, "object:bounds-changed")) {
+       } else if (!g_strcmp0(event->type, "object:bounds-changed")) {
                AtspiRect *rect;
                rect = (AtspiRect *)g_value_get_boxed(&event->any_data);
 
@@ -409,21 +415,18 @@ static void _on_atspi_event_cb(AtspiEvent *event, void *user_data)
                                DEBUG("Window geometry: %d %d", rect->width, rect->height);
                        }
                }
-       }
-       else if (!g_strcmp0(event->type, "object:property-change:accessible-name") && object_has_highlighted_state(event->source)
+       } else if (!g_strcmp0(event->type, "object:property-change:accessible-name") && object_has_highlighted_state(event->source)
                         && (get_objects_attributes(event->source) & ACCESSIBLE_READING_INFO_TYPE_NAME)) {
                gchar *name = atspi_accessible_get_name(event->source, NULL);
                if (!name) {
                        ERROR("name is null");
-                       return;
+                       goto end;
                }
                DEBUG("New name for object, read:%s", name);
                tw_speak_customized(name, EINA_TRUE, EINA_TRUE, event->source, 0);
                g_free(name);
-               return;
-       }
-       // for reading slider and spinner value changes
-       else if (!g_strcmp0(event->type, "object:property-change:accessible-value")) {
+               goto end;
+       } else if (!g_strcmp0(event->type, "object:property-change:accessible-value")) { // for reading slider and spinner value changes
                if (role == ATSPI_ROLE_SLIDER && (get_objects_attributes(event->source) & ACCESSIBLE_READING_INFO_TYPE_DESCRIPTION)) {
                        AtspiValue *value_interface = atspi_accessible_get_value_iface(event->source);
                        _read_value(value_interface);
@@ -432,7 +435,7 @@ static void _on_atspi_event_cb(AtspiEvent *event, void *user_data)
                        gchar *name = atspi_accessible_get_name(event->source, NULL);
                        if (!name) {
                                ERROR("name is null");
-                               return;
+                               goto end;
                        }
                        tw_speak_customized(name, EINA_TRUE, EINA_TRUE, event->source, 0);
                        g_free(name);
@@ -448,15 +451,13 @@ static void _on_atspi_event_cb(AtspiEvent *event, void *user_data)
                        SUPPRESS_FORMAT_ERROR(g_snprintf(buf, sizeof(buf), _("IDS_COM_POP_ITEM_DROPPED_INTO_POSITION_PD_TTS"), idx + 1));
                tw_speak_customized(buf, EINA_TRUE, EINA_TRUE, event->source, 0);
                g_error_free(err);
-       }
-
-       else if (!g_strcmp0(event->type, "object:state-changed:checked")
+       } else if (!g_strcmp0(event->type, "object:state-changed:checked")
                         && (get_objects_attributes(event->source) & ACCESSIBLE_READING_INFO_TYPE_STATE)) {
                char buf[256] = "\0";
                gchar *name = atspi_accessible_get_name(event->source, NULL);
                if (!name) {
                        ERROR("name is null");
-                       return;
+                       goto end;
                }
                g_strlcat(buf, name, sizeof(buf) - strlen(buf) - 1);
                g_strlcat(buf, ", ", sizeof(buf) - strlen(buf) - 1);
@@ -478,7 +479,7 @@ static void _on_atspi_event_cb(AtspiEvent *event, void *user_data)
                gchar *name = atspi_accessible_get_name(event->source, NULL);
                if (!name) {
                        ERROR("name is null");
-                       return;
+                       goto end;
                }
                AtspiAccessible *parent = atspi_accessible_get_parent(event->source, NULL);
                if (role == ATSPI_ROLE_MENU_ITEM) {
@@ -531,14 +532,15 @@ static void _on_atspi_event_cb(AtspiEvent *event, void *user_data)
 
        if (vc_get_keyboard_feedback()) {
                if (role != ATSPI_ROLE_PASSWORD_TEXT && !g_strcmp0(event->type, "object:text-changed:insert")) {
-                       if (!_is_valid_status(event->detail2)) return;
+                       if (!_is_valid_status(event->detail2))
+                               goto end;
                        char buf[256] = "\0";
                        const gchar *text = NULL;
                        const gchar *symtext = NULL;
                        text = g_value_get_string(&event->any_data);
                        if (!text) {
                                ERROR("Received notification about NULL text insert");
-                               return;
+                               goto end;
                        }
                        if ((event->detail2 == 1) && isupper((int)*text)) {
                                SUPPRESS_FORMAT_ERROR(g_snprintf(buf, sizeof(buf), _("IDS_ACCS_OPT_CAPITAL_PS_TTS"), text));
@@ -567,11 +569,12 @@ static void _on_atspi_event_cb(AtspiEvent *event, void *user_data)
                        if (mode != 0)
                                tw_speak(buf, mode == 1);
 
-                       return;
+                       goto end;
                }
                if (role == ATSPI_ROLE_ENTRY) {
                        if (!g_strcmp0(event->type, "object:text-changed:delete")) {
-                               if (!_is_valid_status(event->detail2)) return;
+                               if (!_is_valid_status(event->detail2))
+                                       goto end;
                                char buf[256] = "\0";
                                char buf_deleted[256] = "\0";
                                const gchar *text = NULL;
@@ -581,7 +584,7 @@ static void _on_atspi_event_cb(AtspiEvent *event, void *user_data)
                                text = g_value_get_string(&event->any_data);
                                if (!text) {
                                        ERROR("Received notification about NULL text delete");
-                                       return;
+                                       goto end;
                                }
                                if ((event->detail2 == 1) && isupper((int)*text))
                                        SUPPRESS_FORMAT_ERROR(g_snprintf(buf, sizeof(buf), _("IDS_ACCS_OPT_CAPITAL_PS_TTS"), text));
@@ -611,7 +614,8 @@ static void _on_atspi_event_cb(AtspiEvent *event, void *user_data)
                        }
                } else if (role == ATSPI_ROLE_PASSWORD_TEXT) {
                        if ((!g_strcmp0(event->type, "object:text-changed:insert") || !g_strcmp0(event->type, "object:text-changed:delete"))) {
-                               if (!_is_valid_status(event->detail2)) return;
+                               if (!_is_valid_status(event->detail2))
+                                       goto end;
                                AtspiText *iface_text = NULL;
                                char buf[64] = "\0";
                                iface_text = atspi_accessible_get_text_iface(event->source);
@@ -631,10 +635,11 @@ static void _on_atspi_event_cb(AtspiEvent *event, void *user_data)
        if (new_highlighted_obj && atd->new_obj_highlighted_callback && object_has_highlighted_state(new_highlighted_obj)) {
                DEBUG("HIGHLIGHTED OBJECT IS ABOUT TO CHANGE");
                atd->new_obj_highlighted_callback(new_highlighted_obj, role, atd->new_obj_highlighted_callback_user_data);
-               g_object_unref(new_highlighted_obj);
-               new_highlighted_obj = NULL;
        }
        DEBUG("END");
+end:
+       g_object_unref(new_highlighted_obj);
+       g_boxed_free(ATSPI_TYPE_EVENT, event);
 }
 
 App_Tracker_Data*
@@ -721,6 +726,7 @@ void app_tracker_shutdown(App_Tracker_Data *atd)
                g_source_remove(atd->timer);
 
        g_object_unref(atd->root);
+       g_free(atd->view_content_changed_ecd);
        g_free(atd);
 }
 
@@ -745,7 +751,10 @@ static void app_tracker_context_switch(void *data, AtspiAccessible *root)
        /* unset _scroll_gesture_requrired_obj */
        _object_needs_scroll_gesture_send(atd, NULL);
 
+       g_object_unref(atd->root);
        atd->root = root;
+       g_object_ref(atd->root);
+
        timer_reschedule(atd);
 }
 #endif
index 8301fc760b8b8e174b158a9be08a36ae61147cc5..76daf6e8f95ee342a4c1dbdc088d9b4129c7406c 100644 (file)
@@ -124,6 +124,14 @@ static Eina_Bool _object_is_item(AtspiAccessible *obj)
        return ret;
 }
 
+static void destroy_atspi_relation_set(GArray *relations) {
+       /* This code bases on reverse engeenering of at-spi2-core */
+       for (int i = 0; i< relations->len; ++i) {
+               g_object_unref(g_array_index(relations, AtspiRelation*, i));
+       }
+       g_array_free(relations, TRUE);
+}
+
 static AtspiAccessible *_get_object_in_relation(AtspiAccessible *source, AtspiRelationType search_type)
 {
        GArray *relations;
@@ -148,7 +156,7 @@ static AtspiAccessible *_get_object_in_relation(AtspiAccessible *source, AtspiRe
                                        break;
                                }
                        }
-                       g_array_free(relations, TRUE);
+                       destroy_atspi_relation_set(relations);
                }
        }
        return ret;
@@ -322,27 +330,25 @@ AtspiAccessible *_last(FlatNaviContext *ctx)
        return _directional_depth_first_search(ctx->root, NULL, SEARCH_BACKWARD, _accept_object);
 }
 
-static AtspiAccessible *_navigate_by_one(FlatNaviContext *ctx, search_direction direction)
+static void _navigate_by_one(FlatNaviContext *ctx, search_direction direction)
 {
        if (direction != SEARCH_FORWARD && direction != SEARCH_BACKWARD) {
                ERROR("invalid direction value (%d)", (int)direction);
-               return ctx->current;
+               return;
        }
        DEBUG("START direction %s", direction == SEARCH_FORWARD ? "forward" : "backward");
 
-       AtspiAccessible *root = ctx->root;
-       AtspiAccessible *current = ctx->current;
-       AtspiAccessible *ret = NULL;
-
-       ret = _directional_depth_first_search(root, current, direction, _accept_object);
+       AtspiAccessible *ret = _directional_depth_first_search(ctx->root, ctx->current, direction, _accept_object);
 
-       if (!ret || ret == current) {
+       if (!ret || ret == ctx->current) {
                DEBUG("%s", direction == SEARCH_FORWARD ?
                                                                "Last item reached or failed" :
                                                                "first item reached or failed");
 
                if (ctx->last_entry == (direction == SEARCH_FORWARD ? LAST_ENTRY_LAST : LAST_ENTRY_FIRST)) {
-                       ctx->current = (direction == SEARCH_FORWARD) ? _first(ctx) : _last(ctx);
+                       AtspiAccessible *result = (direction == SEARCH_FORWARD) ? _first(ctx) : _last(ctx);
+                       g_object_unref(ctx->current);
+                       ctx->current = result;
                        ctx->last_entry = LAST_ENTRY_NONE;
                }
                else {
@@ -352,16 +358,16 @@ static AtspiAccessible *_navigate_by_one(FlatNaviContext *ctx, search_direction
 
                        ctx->last_entry = direction == SEARCH_FORWARD ? LAST_ENTRY_LAST : LAST_ENTRY_FIRST;
                }
+               g_object_unref(ret);
        }
        else {
+               g_object_unref(ctx->current);
                ctx->current = ret;
                ctx->last_entry = LAST_ENTRY_NONE;
        }
        char *unique_id = atspi_accessible_get_unique_id(ctx->current, NULL);
        DEBUG("END item %s mode %d", unique_id, ctx->last_entry);
        g_free(unique_id);
-
-       return ret;
 }
 
 FlatNaviContext *flat_navi_context_create()
@@ -384,8 +390,14 @@ int flat_navi_context_setup(FlatNaviContext *ctx, AtspiAccessible *root)
        DEBUG("Creating navigation context for root = %s, root_name = %s", id, root_name);
        g_free(id);
        g_free(root_name);
+
+       g_object_unref(ctx->root);
        ctx->root = root;
+       g_object_ref(ctx->root);
+
+       g_object_unref(ctx->current);
        ctx->current = _first(ctx);
+
        DEBUG("END");
        return 0;
 }
@@ -395,13 +407,17 @@ void flat_navi_context_root_change(FlatNaviContext *ctx, AtspiAccessible *root)
        gchar *id = atspi_accessible_get_unique_id(root, NULL);
        DEBUG("START - context root is changed to %s", id);
        g_free(id);
+       g_object_unref(ctx->root);
        ctx->root = root;
+       g_object_ref(ctx->root);
 }
 
 void flat_navi_context_free(FlatNaviContext *ctx)
 {
        if (!ctx)
                return;
+       g_object_unref(ctx->root);
+       g_object_unref(ctx->current);
        g_free(ctx);
 }
 
@@ -413,7 +429,7 @@ AtspiAccessible *flat_navi_context_root_get(FlatNaviContext *ctx)
        return ctx->root;
 }
 
-const AtspiAccessible *flat_navi_context_first_get(FlatNaviContext *ctx)
+AtspiAccessible *flat_navi_context_first_get(FlatNaviContext *ctx)
 {
        if (!ctx)
                return NULL;
@@ -421,7 +437,7 @@ const AtspiAccessible *flat_navi_context_first_get(FlatNaviContext *ctx)
        return _first(ctx);
 }
 
-const AtspiAccessible *flat_navi_context_last_get(FlatNaviContext *ctx)
+AtspiAccessible *flat_navi_context_last_get(FlatNaviContext *ctx)
 {
        if (!ctx)
                return NULL;
@@ -442,7 +458,9 @@ Eina_Bool flat_navi_context_current_set(FlatNaviContext *ctx, AtspiAccessible *t
        if (!ctx || !target)
                return EINA_FALSE;
 
+       g_object_unref(ctx->current);
        ctx->current = target;
+       g_object_ref(ctx->current);
 
        return EINA_TRUE;
 }
@@ -471,6 +489,8 @@ AtspiAccessible *flat_navi_context_first(FlatNaviContext *ctx)
                return NULL;
 
        AtspiAccessible *ret = _first(ctx);
+
+       g_object_unref(ctx->current);
        ctx->current = ret;
 
        return ret;
@@ -482,6 +502,8 @@ AtspiAccessible *flat_navi_context_last(FlatNaviContext *ctx)
                return NULL;
 
        AtspiAccessible *ret = _last(ctx);
+
+       g_object_unref(ctx->current);
        ctx->current = ret;
 
        return ret;
index e016627de5e9889a5e49ff442612afff49f77f2c..486626d8b57c8cf63c6092367dc2c2bcef7a6607 100644 (file)
@@ -25,7 +25,6 @@
 
 struct _KeyboardTrackerData
 {
-       AtspiDeviceListener *listener;
        AtspiDeviceListener *async_listener;
        Eldbus_Connection *conn;
        Eldbus_Service_Interface *iface;
@@ -57,18 +56,25 @@ static const Eldbus_Service_Interface_Desc iface_desc = {
 static gboolean async_keyboard_cb(const AtspiDeviceEvent *stroke, void *data)
 {
        DEBUG("AT-SPI DEVICE EVENT: ID(%d) STRING(%s) TYPE(%d) HW_CODE(%d) MODIFIERS(%d) TIMESTAMP(%d)", stroke->id, stroke->event_string, stroke->type, stroke->hw_code, stroke->modifiers, stroke->timestamp);
+
+       gboolean result = FALSE;
+
        if (!g_strcmp0(stroke->event_string, "XF86Back")) {
                tw_speak(_("MIDS_MH_BODY_BACK_BUTTON_T_TTS"), EINA_TRUE);
-               return TRUE;
+               result = TRUE;
        } else if (!g_strcmp0(stroke->event_string, "XF86PowerOff")) {
                tw_purge(EINA_FALSE);
-               return TRUE;
+               result = TRUE;
        } else if (!g_strcmp0(stroke->event_string, "XF86AudioPause")) {
                Eina_Bool paused = tw_pause_get();
                tw_pause_set(!paused);
-               return TRUE;
-       } else
-               return FALSE;
+               result = TRUE;
+       }
+
+       /* There is bug in the api. stroke does not point to const values */
+       g_boxed_free(ATSPI_TYPE_DEVICE_EVENT, (AtspiDeviceEvent*)stroke);
+
+       return result;
 }
 
 static void keyboard_changed_cb(keynode_t *node, void *user_data)
@@ -141,20 +147,17 @@ KeyboardTrackerData* keyboard_tracker_init(void)
 
        if (ktd->async_listener == NULL) {
                ERROR("atspi_device_listener_new() failed, async_listener not set");
-               free(ktd);
-               return NULL;
+               goto fail_listener;
        }
 
        atspi_register_keystroke_listener(ktd->async_listener, NULL, 0, 1 << ATSPI_KEY_RELEASED_EVENT, ATSPI_KEYLISTENER_NOSYNC, NULL);
 
-
        eldbus_init();
        ktd->conn = eldbus_connection_get(ELDBUS_CONNECTION_TYPE_SESSION);
 
        if (ktd->conn == NULL) {
                ERROR("ELDBUS CONNECTION NOT ESTABLISHED");
-               free(ktd);
-               return NULL;
+               goto fail_connection;
        }
 
        eldbus_name_request(ktd->conn, E_KEYBOARD_SERVICE_BUS_NAME, ELDBUS_NAME_REQUEST_FLAG_DO_NOT_QUEUE, NULL, NULL);
@@ -162,14 +165,24 @@ KeyboardTrackerData* keyboard_tracker_init(void)
 
        if (!ktd->iface) {
                ERROR("ELDBUS INTERFACE NOT REGISTERED");
-               free(ktd);
-               return NULL;
+               goto fail_iface;
        }
        _set_vconf_key_changed_callback_keyboard_status(ktd);
 
        DEBUG("keyboard tracker init");
 
        return ktd;
+
+fail_iface:
+       eldbus_name_release(ktd->conn, E_KEYBOARD_SERVICE_BUS_NAME, NULL, NULL);
+       eldbus_connection_unref(ktd->conn);
+fail_connection:
+       eldbus_shutdown();
+       atspi_deregister_keystroke_listener(ktd->async_listener, NULL, 0, 1 << ATSPI_KEY_RELEASED_EVENT, NULL);
+       g_object_unref(ktd->async_listener);
+fail_listener:
+       free(ktd);
+       return NULL;
 }
 
 void keyboard_tracker_shutdown(KeyboardTrackerData *ktd)
@@ -177,9 +190,10 @@ void keyboard_tracker_shutdown(KeyboardTrackerData *ktd)
        if (ktd == NULL)
                return;
 
-       atspi_deregister_keystroke_listener(ktd->listener, NULL, 0, 1 << ATSPI_KEY_PRESSED, NULL);
        atspi_deregister_keystroke_listener(ktd->async_listener, NULL, 0, 1 << ATSPI_KEY_RELEASED_EVENT, NULL);
+       g_object_unref(ktd->async_listener);
 
+       eldbus_service_interface_unregister(ktd->iface);
        eldbus_name_release(ktd->conn, E_KEYBOARD_SERVICE_BUS_NAME, NULL, NULL);
        eldbus_connection_unref(ktd->conn);
        eldbus_shutdown();
index d8b564dd9b27fd97f4c50ff3fb61e0686787c54b..15524393ba9f4c0c1976ed405f04fa0ead8cf38c 100644 (file)
@@ -256,8 +256,6 @@ TIZEN_PROD_STATIC void _send_highlighted_object_info(NavigatorData *nd, AtspiAcc
        Eldbus_Connection *conn;
        Eldbus_Object *dobj;
        Eldbus_Proxy *proxy;
-       AtspiRect *rect = NULL;
-       AtspiComponent *comp = NULL;
        int highlighted_object_x = -1;
        int highlighted_object_y = -1;
        AtspiRole role = -1;
@@ -278,10 +276,14 @@ TIZEN_PROD_STATIC void _send_highlighted_object_info(NavigatorData *nd, AtspiAcc
        role = atspi_accessible_get_role(obj, NULL);
        /* when you change this condition, check _current_highlight_object_set */
        if (role != ATSPI_ROLE_POPUP_MENU && role != ATSPI_ROLE_DIALOG) { /* ctxpopup outline does not show highlight frame */
-               comp = atspi_accessible_get_component_iface(obj);
-               rect = atspi_component_get_extents(comp, ATSPI_COORD_TYPE_SCREEN, NULL);
+               AtspiComponent *comp = atspi_accessible_get_component_iface(obj);
+               AtspiRect *rect = atspi_component_get_extents(comp, ATSPI_COORD_TYPE_SCREEN, NULL);
+
                highlighted_object_x = rect->x + rect->width / 2;
                highlighted_object_y = rect->y + rect->height / 2;
+
+               g_boxed_free(ATSPI_TYPE_RECT, rect);
+               g_object_unref(comp);
        }
 
        keyboard_status = keyboard_event_status(nd->keyboard_tracker_data, info->x_end, info->y_end);
@@ -415,6 +417,7 @@ TIZEN_PROD_STATIC void _current_highlight_object_set(NavigatorData *nd, AtspiAcc
                        g_clear_object(&nd->current_comp);
                        g_clear_error(&err);
                }
+               g_object_unref(nd->current_obj);
                nd->current_obj = NULL;
                DEBUG("END");
                return;
@@ -452,10 +455,12 @@ TIZEN_PROD_STATIC void _current_highlight_object_set(NavigatorData *nd, AtspiAcc
 
                /* Sync(set) current_comp, and current_obj.
                The obj is about to grab highlight */
+               g_object_unref(nd->current_comp);
                nd->current_comp = comp;
                g_clear_object(&(nd->current_obj));
                nd->current_obj = obj;
-               flat_navi_context_current_set(nd->flat_navi_context, g_object_ref(nd->current_obj));
+               g_object_ref(nd->current_obj);
+               flat_navi_context_current_set(nd->flat_navi_context, nd->current_obj);
 
                role = atspi_accessible_get_role(obj, NULL);
                /* when you change this condition, check _send_highlighted_object_info */
@@ -555,24 +560,25 @@ TIZEN_PROD_STATIC void _window_at_point_check(NavigatorData *nd, int x, int y)
 TIZEN_PROD_STATIC void _focus_widget(NavigatorData *nd, Gesture_Info *info)
 {
        DEBUG("START");
+       AtspiAccessible *obj = NULL;
 
        _window_at_point_check(nd, info->x_beg, info->y_beg);
 
        if ((nd->last_focus.x == info->x_beg) && (nd->last_focus.y == info->y_beg))
                return;
 
-       AtspiAccessible *obj = NULL;
        if (flat_navi_context_current_at_x_y_set(nd->flat_navi_context, info->x_beg, info->y_beg, &obj)) {
                /* Need to check active_window_context->timer, other conditions could
                increase number of IPC, if you need to reduce IPC count, then check the
                active_window_context->timer only here in the future. */
                AppTrackerContextValidility val = app_tracker_context_valid_check(nd->app_tracker_data);
                if (val == APP_TRACKER_CONTEXT_NOT_VALID)
-                       return;
+                       goto end;
 
                _current_highlight_object_set(nd, obj, info->type == ONE_FINGER_SINGLE_TAP ? HIGHLIGHT_POINT_AGAIN : HIGHLIGHT_POINT);
        }
-
+end:
+       g_object_unref(obj);
        DEBUG("END");
 }
 
@@ -1572,6 +1578,7 @@ TIZEN_PROD_STATIC void _set_pause(void)
 TIZEN_PROD_STATIC void auto_review_highlight_set(NavigatorData *nd)
 {
        AtspiAccessible *obj = flat_navi_context_next(nd->flat_navi_context);
+       AtspiAccessible *ref = NULL;
 
        DEBUG("START");
 
@@ -1579,11 +1586,13 @@ TIZEN_PROD_STATIC void auto_review_highlight_set(NavigatorData *nd)
                DEBUG("obj == NULL");
                nd->auto_review_on = false;
                return;
-       } else if (obj == flat_navi_context_last_get(nd->flat_navi_context)) {
+       } else if (obj == (ref = flat_navi_context_last_get(nd->flat_navi_context))) {
                DEBUG("obj == flat_navi_context_last_get()");
                nd->auto_review_on = false;
        }
 
+       g_object_unref(ref);
+
        _current_highlight_object_set(nd, obj, HIGHLIGHT_FIRST);
 
        DEBUG("END");
@@ -1702,9 +1711,7 @@ TIZEN_PROD_STATIC void _direct_scroll_back(NavigatorData *nd)
                obj = atspi_accessible_get_child_at_index(parent, 0, NULL);
                if (vc_get_sound_feedback())
                        smart_notification(FOCUS_CHAIN_END_NOTIFICATION_EVENT, 0, 0);
-       }
-
-       else {
+       } else {
                DEBUG("go back to %d element", index);
                obj = atspi_accessible_get_child_at_index(parent, index, NULL);
        }
@@ -1715,6 +1722,8 @@ TIZEN_PROD_STATIC void _direct_scroll_back(NavigatorData *nd)
                        DEBUG("current obj set");
                _current_highlight_object_set(nd, obj, HIGHLIGHT_FIRST);
        }
+
+       g_object_unref(obj);
        g_object_unref(parent);
        g_object_unref(current);
 }
@@ -1935,8 +1944,6 @@ TIZEN_PROD_STATIC void _move_slider(NavigatorData *nd, Gesture_Info *gi)
        }
 
        AtspiAccessible *obj = NULL;
-       AtspiComponent *comp = NULL;
-       AtspiRect *rect = NULL;
        gint total_distance = 0;
        obj = nd->current_obj;
 
@@ -1962,7 +1969,7 @@ TIZEN_PROD_STATIC void _move_slider(NavigatorData *nd, Gesture_Info *gi)
        }
 
        if (gi->state == 0) {
-               comp = atspi_accessible_get_component_iface(obj);
+               AtspiComponent *comp = atspi_accessible_get_component_iface(obj);
                if (!comp) {
                        ERROR("that slider do not have component interface");
                        nd->prepared = false;
@@ -1970,7 +1977,7 @@ TIZEN_PROD_STATIC void _move_slider(NavigatorData *nd, Gesture_Info *gi)
                        return;
                }
 
-               rect = atspi_component_get_extents(comp, ATSPI_COORD_TYPE_SCREEN, NULL);
+               AtspiRect *rect = atspi_component_get_extents(comp, ATSPI_COORD_TYPE_SCREEN, NULL);
 
                DEBUG("Current object is in:%d %d", rect->x, rect->y);
                DEBUG("Current object has size:%d %d", rect->width, rect->height);
@@ -1987,6 +1994,7 @@ TIZEN_PROD_STATIC void _move_slider(NavigatorData *nd, Gesture_Info *gi)
                        nd->slider_offset = 0.0;
                g_object_unref(value_interface);
                g_free(rect);
+               g_object_unref(comp);
        }
 
        if (gi->state == 1) {
@@ -2562,6 +2570,7 @@ void sound_n_vibration_feedback_generate(AtspiAccessible *obj)
                        DEBUG("HIGHLIGHT_NOTIFICATION_EVENT");
                        smart_notification(HIGHLIGHT_NOTIFICATION_EVENT, 0, 0);
                }
+               g_object_unref(action);
        }
 
        if (vc_get_haptic())
@@ -2664,6 +2673,7 @@ void navigator_shutdown(NavigatorData *nd)
                AtspiComponent *comp = atspi_accessible_get_component_iface(nd->current_obj);
                if (comp) {
                        atspi_component_clear_highlight(comp, &err);
+                       g_object_unref(comp);
                        GERROR_CHECK(err);
                }
        }
@@ -2684,6 +2694,9 @@ void navigator_shutdown(NavigatorData *nd)
        app_tracker_shutdown(nd->app_tracker_data);
        smart_notification_shutdown();
 
+       g_object_unref(nd->current_comp);
+       g_object_unref(nd->current_obj);
+
        free(nd);
 }
 
index e0c20cddcabde5e3cbc781717b09b7fe8186e679..24204890e646b43bffb8993ef2adbfb65f33ab97 100644 (file)
@@ -191,20 +191,24 @@ static char *spi_on_value_changed_get_text(SpiData *spi, AtspiEvent *event)
                        DEBUG("MAX VALUE REACHED");
                        if (asprintf(&text_to_read, "%.2f %s", current_temp_value, _("IDS_REACHED_MAX_VAL")) < 0) {
                                ERROR(MEMORY_ERROR);
+                               g_object_unref(value_interface);
                                return NULL;
                        }
                } else if (abs(current_temp_value - atspi_value_get_minimum_value(value_interface, NULL)) < EPS) {
                        DEBUG("MIN VALUE REACHED");
                        if (asprintf(&text_to_read, "%.2f %s", current_temp_value, _("IDS_REACHED_MIN_VAL")) < 0) {
                                ERROR(MEMORY_ERROR);
+                               g_object_unref(value_interface);
                                return NULL;
                        }
                } else {*/
                if (asprintf(&text_to_read, "%.2f", current_temp_value) < 0) {
                        ERROR(MEMORY_ERROR);
+                       g_object_unref(value_interface);
                        return NULL;
                }
                //}
+               g_object_unref(value_interface);
        }
 
        return text_to_read;
@@ -321,18 +325,19 @@ static Eina_Bool _signal_handling_timer_cb(void *data)
        return ECORE_CALLBACK_CANCEL;
 }
 
-void spi_event_listener_cb(AtspiEvent *event, void *user_data)
+static void spi_event_listener_cb(AtspiEvent *event, void *user_data)
 {
        DEBUG("START");
+
        if (!user_data) {
                ERROR("Invalid parameter");
-               return;
+               goto end;
        }
 
        SpiData *spi = (SpiData *) user_data;
        if (!spi->tracking_signal_name) {
                ERROR("Invalid tracking signal name");
-               return;
+               goto end;
        }
 
        DEBUG("Tracking signal - %s", spi->tracking_signal_name);
@@ -346,19 +351,22 @@ void spi_event_listener_cb(AtspiEvent *event, void *user_data)
                g_free(text_to_read);
                g_free(desc_to_read);
                DEBUG("END - No text to read");
-               return;
+               goto end;
        }
 
        // continue function if cancel == 1 or signal_handling_timer == 0
-       if (!cancel && spi->signal_handling_timer)
-               return;
+       if (!cancel && spi->signal_handling_timer) {
+               g_free(text_to_read);
+               g_free(desc_to_read);
+               goto end;
+       }
 
        // this function will free text_to_read and desc_to_read if fails
        // (looks like very bad desing to me)
        SignalHandlingTimerData *shtd = create_shtd(spi, event->source, text_to_read, desc_to_read);
        if (!shtd) {
                DEBUG("Error - create_shtd failed");
-               return;
+               goto end;
        }
 
        DEBUG("Stop current reading and add timer");
@@ -383,10 +391,12 @@ void spi_event_listener_cb(AtspiEvent *event, void *user_data)
        if (!spi->signal_handling_timer) {
                DEBUG("Error - ecore_timer_add failed");
                free_shtd(shtd);
-               return;
+               goto end;
        }
 
        DEBUG("END - Timer added (text:%s desc:%s source:%p)", text_to_read, desc_to_read ? desc_to_read : "null", event->source);
+end:
+       g_boxed_free(ATSPI_TYPE_EVENT, event);
 }
 
 /**
index 9def0067d737147eba8bdf12c2275aca2fc9a263..c06477a2e99ac28ee33d409d462b89ea4fae42cc 100644 (file)
@@ -61,6 +61,11 @@ static void tapi_init(System_Data *system_data)
                system_data->tapi_handle[i] = tel_init(cp_list[i]);
                DEBUG("CP_LIST %d = %s", i, cp_list[i]);
        }
+
+       for (i = 0; cp_list[i]; ++i)
+               g_free(cp_list[i]);
+
+       g_free(cp_list);
 }
 
 /**
@@ -72,7 +77,7 @@ System_Data *system_notifications_init(void)
        DEBUG("******************** START ********************");
 
        int ret = -1;
-       System_Data *system_data = malloc(sizeof(System_Data));
+       System_Data *system_data = calloc(sizeof(System_Data), 1);
 
        if (!system_data) {
                ERROR("malloc(%zu) failed", sizeof(System_Data));
@@ -134,17 +139,22 @@ void system_notifications_shutdown(System_Data *system_data)
        if (ret != BT_ERROR_NONE)
                ERROR("ret == %d", ret);
 
-       if (system_data) {
-               if (system_data->wifi) {
-                       ret = wifi_manager_deinitialize(system_data->wifi);
-                       if (ret != WIFI_MANAGER_ERROR_NONE)
-                               ERROR("wifi ret == %d", ret);
-               }
+       if (!system_data)
+               return;
+    
+       if (system_data->wifi) {
+               ret = wifi_manager_deinitialize(system_data->wifi);
+               if (ret != WIFI_MANAGER_ERROR_NONE)
+                       ERROR("wifi ret == %d", ret);
+       }
 
-               system_data->wifi = NULL;
-               free(system_data);
+       for (int i=0; i<(MAX_SIM_COUNT+1) && system_data->tapi_handle[i]; ++i) {
+               tel_deinit(system_data->tapi_handle[i]);
        }
 
+       system_data->wifi = NULL;
+       free(system_data);
+
        return;
 }
 
index 524633780d935f2a0b7d7851f3cf782d70bb71e8..da0ad79aa3e936de734a42a0f02e045a1ff4b4d8 100644 (file)
@@ -112,7 +112,6 @@ void get_realized_items_count(AtspiAccessible *scrollable_object, int *start_idx
 {
        DEBUG("START");
        int count_child, jdx;
-       AtspiAccessible *child_iter;
        AtspiStateType state = ATSPI_STATE_SHOWING;
 
        if (!scrollable_object) {
@@ -123,13 +122,15 @@ void get_realized_items_count(AtspiAccessible *scrollable_object, int *start_idx
        count_child = atspi_accessible_get_child_count(scrollable_object, NULL);
 
        for (jdx = 0; jdx < count_child; jdx++) {
-               child_iter = atspi_accessible_get_child_at_index(scrollable_object, jdx, NULL);
-               if (!child_iter)
+               AtspiAccessible *child = atspi_accessible_get_child_at_index(scrollable_object, jdx, NULL);
+               if (!child)
                        continue;
 
-               AtspiStateSet *state_set = atspi_accessible_get_state_set(child_iter);
+               AtspiStateSet *state_set = atspi_accessible_get_state_set(child);
                gboolean is_visible = atspi_state_set_contains(state_set, state);
+
                g_clear_object(&state_set);
+               g_object_unref(child);
 
                if (is_visible) {
                        *start_idx = jdx;
@@ -150,7 +151,7 @@ void get_realized_items_count(AtspiAccessible *scrollable_object, int *start_idx
 static void _scroll_event_cb(AtspiEvent *event, gpointer user_data)
 {
        if (!status)
-               return;
+               goto end;
 
        int start_index, end_index;
        start_index = 0;
@@ -171,6 +172,8 @@ static void _scroll_event_cb(AtspiEvent *event, gpointer user_data)
                get_realized_items_count((AtspiAccessible *) event->source, &start_index, &end_index);
                _smart_notification_realized_items(start_index, end_index);
        }
+end:
+       g_boxed_free(ATSPI_TYPE_EVENT, event);
 }
 
 /**
index 9897244b180e6fbfa60df8824c80bec1cd5ef30d..c790e87c3286ea3ca7eac450326a252e0ffa7fe9 100644 (file)
@@ -105,6 +105,7 @@ static Eina_Bool _window_need_to_be_purged(WindowInfo *wi)
        }
        GError *err = NULL;
        AtspiRect *rect = atspi_component_get_extents(comp, ATSPI_COORD_TYPE_SCREEN, &err);
+       g_object_unref(comp);
        GERROR_CHECK(err);
        if (!rect) {
                DEBUG("purging because failed to get extents");
@@ -212,6 +213,7 @@ static void _window_append(WindowTrackerData *wtd, AtspiAccessible *window, Eina
        /* should be ATSPI_COORD_TYPE_SCREEN, but it seems that evas_object_geometry
        would be same with ecore_evas_geometry for window. so the value is doubled */
        rect = atspi_component_get_extents(comp, ATSPI_COORD_TYPE_SCREEN, NULL);
+       g_object_unref(comp);
 
        wi = g_malloc0(sizeof(WindowInfo));
        if (!wi) {
@@ -358,8 +360,7 @@ static void _on_atspi_window_cb(AtspiEvent *event, void *user_data)
                        (window_activate_info_type & ACCESSIBLE_WINDOW_ACTIVATE_INFO_KEYBOARD);
                if (keyboard_window_activated) {
                        wtd->keyboard_window = g_object_ref(event->source);
-                       g_free(name);
-                       return;
+                       goto end;
                }
                _window_append(wtd, event->source, EINA_TRUE, EINA_FALSE, window_activate_info_type);
                wtd->subroot = NULL; //No need to keep subroot if any window gets activated
@@ -406,7 +407,9 @@ static void _on_atspi_window_cb(AtspiEvent *event, void *user_data)
                        }
                }
        }
+end:
        g_free(name);
+       g_boxed_free(ATSPI_TYPE_EVENT, event);
 }
 
 WindowTrackerData *window_tracker_init(void)