screen_reader_system: fix dereference error 81/239081/1
authorKamil Konieczny <k.konieczny@samsung.com>
Tue, 21 Jul 2020 12:48:27 +0000 (14:48 +0200)
committerKamil Konieczny <k.konieczny@samsung.com>
Tue, 21 Jul 2020 12:58:16 +0000 (14:58 +0200)
In shutdown function, variable system_data was freed and
later dereferenced.

Change-Id: I6727bb9134971c107b7a0e22c81020867b375795

src/screen_reader_system.c

index f99151a4b4272e7261b0033b0ebf2df5285091ca..4f8a462f295cb2f6b4d6c089cac69ae073297d1e 100644 (file)
@@ -123,9 +123,6 @@ void system_notifications_shutdown(System_Data *system_data)
 {
        int ret = -1;
 
-       if (system_data)
-               free(system_data);
-
        // BATTERY LOW/FULL
        device_remove_callback(DEVICE_CALLBACK_BATTERY_LEVEL, device_system_cb);
        // BATTERY CHARGING/NOT-CHARGING
@@ -137,10 +134,16 @@ void system_notifications_shutdown(System_Data *system_data)
        if (ret != BT_ERROR_NONE)
                ERROR("ret == %d", ret);
 
-       ret = wifi_manager_deinitialize(system_data->wifi);
-       if (ret != WIFI_MANAGER_ERROR_NONE)
-               ERROR("ret == %d", ret);
-       system_data->wifi = NULL;
+       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);
+               }
+
+               system_data->wifi = NULL;
+               free(system_data);
+       }
 
        return;
 }