screen_reader: check NULL when g_object_ref/unref are called. 20/306520/1
authorHosang Kim <hosang12.kim@samsung.com>
Wed, 21 Feb 2024 09:22:44 +0000 (18:22 +0900)
committerArtur Świgoń <a.swigon@samsung.com>
Thu, 22 Feb 2024 10:21:40 +0000 (11:21 +0100)
Sometimes g_boject_ref/unref are called with NULL object.

Change-Id: Ia9ca8b341fc78a9481f201f29d936bdb15100b07

src/app_tracker.c
src/flat_navi.c
src/navigator.c
src/screen_reader_tts.c

index 83bfa5223789179fb21f67411a5d2dabc66ed704..cef2f59fd9cad9eb175ef2cce96482de27bbb40a 100644 (file)
@@ -176,6 +176,8 @@ static Eina_Bool _read_cb(void *data)
 {
        DEBUG("START");
        App_Tracker_Data *atd = (App_Tracker_Data*)data;
+       if (!atd->read_timer_user_data) return ECORE_CALLBACK_CANCEL;
+
        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);
@@ -283,7 +285,8 @@ static void _on_atspi_event_cb(AtspiEvent *event, void *user_data)
                        if (atd->read_timer)
                                ecore_timer_del(atd->read_timer);
 
-                       g_object_unref(atd->read_timer_user_data);
+                       if (atd->read_timer_user_data)
+                               g_object_unref(atd->read_timer_user_data);
                        atd->read_timer_user_data = new_highlighted_obj;
                        g_object_ref(atd->read_timer_user_data);
 
@@ -300,7 +303,8 @@ static void _on_atspi_event_cb(AtspiEvent *event, void *user_data)
                                ecore_timer_del(atd->read_timer);
                                atd->read_timer = NULL;
 
-                               g_object_unref(atd->read_timer_user_data);
+                               if (atd->read_timer_user_data)
+                                       g_object_unref(atd->read_timer_user_data);
                                atd->read_timer_user_data = NULL;
                        }
 
@@ -600,7 +604,7 @@ static void _on_atspi_event_cb(AtspiEvent *event, void *user_data)
        }
        DEBUG("END");
 end:
-       g_object_unref(new_highlighted_obj);
+       if (new_highlighted_obj) g_object_unref(new_highlighted_obj);
        g_boxed_free(ATSPI_TYPE_EVENT, event);
 }
 
@@ -719,7 +723,7 @@ 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);
+       if (atd->root) g_object_unref(atd->root);
        atd->root = root;
        g_object_ref(atd->root);
 
index 4d5fcb8e97152d466e8a2d34e024649eecee2b2f..7270ebeba95d5d24f7c2f6a1df8225719e44c7ba 100644 (file)
@@ -326,7 +326,7 @@ AtspiAccessible *_last(FlatNaviContext *ctx)
 static void _on_chain_end_loop(FlatNaviContext *ctx, search_direction direction)
 {
        AtspiAccessible *result = (direction == SEARCH_FORWARD) ? _first(ctx) : _last(ctx);
-       g_object_unref(ctx->current);
+       if (ctx->current) g_object_unref(ctx->current);
        ctx->current = result;
        ctx->last_entry = LAST_ENTRY_NONE;
 }
@@ -396,10 +396,10 @@ static void _navigate_by_one(FlatNaviContext *ctx, search_direction direction)
 
                        ctx->last_entry = direction == SEARCH_FORWARD ? LAST_ENTRY_LAST : LAST_ENTRY_FIRST;
                }
-               g_object_unref(ret);
+               if (ret) g_object_unref(ret);
        }
        else {
-               g_object_unref(ctx->current);
+               if (ctx->current) g_object_unref(ctx->current);
                ctx->current = ret;
                ctx->last_entry = LAST_ENTRY_NONE;
        }
@@ -443,12 +443,12 @@ int flat_navi_context_setup(FlatNaviContext *ctx, AtspiAccessible *root)
        ctx->root = root;
        g_object_ref(ctx->root);
 
-       g_object_unref(ctx->current);
+       if (ctx->current) g_object_unref(ctx->current);
        if (_return_to_old_root(old_root)) {
                DEBUG("Will return to old root");
                ctx->current = old_root;
        } else {
-               g_object_unref(old_root);
+               if (old_root) g_object_unref(old_root);
                ctx->current = _first(ctx);
        }
        ctx->last_entry = LAST_ENTRY_NONE;
@@ -462,7 +462,7 @@ 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);
+       if (ctx->root) g_object_unref(ctx->root);
        ctx->root = root;
        g_object_ref(ctx->root);
 }
@@ -513,7 +513,7 @@ Eina_Bool flat_navi_context_current_set(FlatNaviContext *ctx, AtspiAccessible *t
        if (!ctx || !target)
                return EINA_FALSE;
 
-       g_object_unref(ctx->current);
+       if (ctx->current) g_object_unref(ctx->current);
        ctx->current = target;
        g_object_ref(ctx->current);
 
@@ -545,7 +545,7 @@ AtspiAccessible *flat_navi_context_first(FlatNaviContext *ctx)
 
        AtspiAccessible *ret = _first(ctx);
 
-       g_object_unref(ctx->current);
+       if (ctx->current) g_object_unref(ctx->current);
        ctx->current = ret;
 
        return ret;
@@ -558,7 +558,7 @@ AtspiAccessible *flat_navi_context_last(FlatNaviContext *ctx)
 
        AtspiAccessible *ret = _last(ctx);
 
-       g_object_unref(ctx->current);
+       if (ctx->current) g_object_unref(ctx->current);
        ctx->current = ret;
 
        return ret;
index 66ff9ed97e9f2013e7da1012b9dfa02a64781978..c2d9ced3338c7b7d3d06c89cefc2cf13038284e3 100644 (file)
@@ -416,7 +416,8 @@ 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);
+               if (nd->current_obj)
+                       g_object_unref(nd->current_obj);
                nd->current_obj = NULL;
                DEBUG("END");
                return;
@@ -451,11 +452,11 @@ TIZEN_PROD_STATIC void _current_highlight_object_set(NavigatorData *nd, AtspiAcc
                        DEBUG("clearing highlight for %s", id);
                        g_free(id);
                        atspi_component_clear_highlight(nd->current_comp, &err);
+                       g_object_unref(nd->current_comp);
                }
 
                /* 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;
@@ -561,7 +562,7 @@ TIZEN_PROD_STATIC void _focus_widget(NavigatorData *nd, Gesture_Info *info)
                _current_highlight_object_set(nd, obj, info->type == ONE_FINGER_SINGLE_TAP ? HIGHLIGHT_POINT_AGAIN : HIGHLIGHT_POINT);
        }
 end:
-       g_object_unref(obj);
+       if (obj) g_object_unref(obj);
        DEBUG("END");
 }
 
@@ -1601,7 +1602,7 @@ TIZEN_PROD_STATIC void auto_review_highlight_set(NavigatorData *nd)
                nd->auto_review_on = false;
        }
 
-       g_object_unref(ref);
+       if (ref) g_object_unref(ref);
 
        _current_highlight_object_set(nd, obj, HIGHLIGHT_FIRST);
 
@@ -1731,9 +1732,9 @@ TIZEN_PROD_STATIC void _direct_scroll_back(NavigatorData *nd)
                if (flat_navi_context_current_set(nd->flat_navi_context, obj))
                        DEBUG("current obj set");
                _current_highlight_object_set(nd, obj, HIGHLIGHT_FIRST);
+               g_object_unref(obj);
        }
 
-       g_object_unref(obj);
        g_object_unref(parent);
        g_object_unref(current);
 }
@@ -1802,6 +1803,7 @@ TIZEN_PROD_STATIC void _direct_scroll_forward(NavigatorData *nd)
                if (flat_navi_context_current_set(nd->flat_navi_context, obj))
                        DEBUG("current obj set");
                _current_highlight_object_set(nd, obj, HIGHLIGHT_LAST);
+               g_object_unref(obj);
        }
        g_object_unref(parent);
        g_object_unref(current);
@@ -2511,10 +2513,12 @@ TIZEN_PROD_STATIC void _view_content_changed(AtspiAccessible *root, AtspiRole ro
                return;
        }
 
-       AtspiAccessible *old_root = g_object_ref(flat_navi_context_root_get(nd->flat_navi_context));
+       AtspiAccessible *old_root = NULL;
+       if (flat_navi_context_root_get(nd->flat_navi_context))
+               old_root = g_object_ref(flat_navi_context_root_get(nd->flat_navi_context));
        if (flat_navi_context_setup(nd->flat_navi_context, root)) {
                DEBUG("END -- setup failed");
-               g_object_unref(old_root);
+               if (old_root) g_object_unref(old_root);
                return;
        }
        AtspiAccessible *new_current = flat_navi_context_current_get(nd->flat_navi_context);
@@ -2522,7 +2526,7 @@ TIZEN_PROD_STATIC void _view_content_changed(AtspiAccessible *root, AtspiRole ro
                // when returning to old context root as current in new context we should highlight the current immediately without providing default label
                default_label_enabled = EINA_FALSE;
        }
-       g_object_unref(old_root);
+       if (old_root) g_object_unref(old_root);
 
        if (default_label_enabled) {
                _current_highlight_object_set(nd, NULL, HIGHLIGHT_FIRST);
@@ -2577,11 +2581,11 @@ void sound_n_vibration_feedback_generate(AtspiAccessible *obj)
                if (action) {
                        DEBUG("HIGHLIGHT_NOTIFICATION_EVENT_ACTIONABLE");
                        smart_notification(HIGHLIGHT_NOTIFICATION_EVENT_ACTIONABLE, 0, 0);
+                       g_object_unref(action);
                } else {
                        DEBUG("HIGHLIGHT_NOTIFICATION_EVENT");
                        smart_notification(HIGHLIGHT_NOTIFICATION_EVENT, 0, 0);
                }
-               g_object_unref(action);
        }
 
        if (vc_get_haptic())
@@ -2701,8 +2705,8 @@ 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);
+       if (nd->current_comp) g_object_unref(nd->current_comp);
+       if (nd->current_obj) g_object_unref(nd->current_obj);
 
        free(nd);
 }
index e2b90635456caff7a1581bcc7a81ed8bc1d838bf..6c03b26aaf5059b41f825694d69a783619e1cc8a 100644 (file)
@@ -240,7 +240,7 @@ static void dispose_read_command(Read_Command *command, Signal playing_reason, S
                        // by eina_strbuf_string_steal().
                        free(command->context.text);
                }
-               g_object_unref(command->obj);
+               if (command->obj) g_object_unref(command->obj);
                g_free(command);
        }
 }
@@ -782,7 +782,7 @@ tw_speak_customized(const char *text_to_speak, Eina_Bool want_discard_previous_r
        rc->discardable = discardable;
        rc->want_discard_previous_reading = want_discard_previous_reading;
        rc->is_playing = EINA_FALSE;
-       rc->obj = g_object_ref(obj);
+       if (obj) rc->obj = g_object_ref(obj);
        rc->time_to_speak = 0;
        rc->delay_to_speak = delay;
        if (delay) {