[SDL_Tizen] Fix coverity issue
[platform/upstream/SDL.git] / src / core / tizen / SDL_tizen.c
index 6b561bc..1f1ad18 100644 (file)
@@ -40,6 +40,9 @@ static appcore_context_h appcore_handle = NULL;
 static ui_app_lifecycle_callback_s event_callback = {0,};
 static app_event_handler_h handlers[5] = {NULL, };
 
+static app_control_h event_app_control;
+static SDL_bool app_control_init = 0;
+
 int _tizen_terminate_event_filter(void *userdata, SDL_Event * event);
 int _tizen_aul_status_changed_cb(int status, void *data);
 
@@ -87,10 +90,18 @@ _tizen_sdl_control(app_control_h app_control, void *data)
     SDL_memset(&event, 0, sizeof(event));
     event.type = SDL_APP_CONTROL;
     event.user.code = 0;
-    event.user.data1 = (void*)app_control;
+
+    if(app_control_init == 1)
+        app_control_destroy(event_app_control);
+
+    app_control_clone(&event_app_control, app_control);
+    app_control_init = 1;
+
+    event.user.data1 = (void*)event_app_control;
     event.user.data2 = (void*)data;
 
     SDL_PushEvent(&event);
+
     return;
 }
 
@@ -104,7 +115,12 @@ _tizen_app_lang_changed(app_event_info_h event_info, void *user_data)
     SDL_memset(&event, 0, sizeof(event));
     event.type = SDL_APP_LANGUAGE_CHANGED;
     event.user.code = 0;
-    event.user.data1 = (void*)event_info;
+    char* language;
+    int ret = app_event_get_language(event_info, &language);
+    if(ret != APP_ERROR_NONE) {
+        SDL_LogError(SDL_LOG_CATEGORY_ERROR, "app_event_get_language() failed. Err = %d.", ret);
+    }
+    event.user.data1 = (void*)language;
     event.user.data2 = (void*)user_data;
 
     SDL_PushEvent(&event);
@@ -141,7 +157,9 @@ _tizen_app_region_changed(app_event_info_h event_info, void *user_data)
     SDL_memset(&event, 0, sizeof(event));
     event.type = SDL_APP_REGION_CHANGED;
     event.user.code = 0;
-    event.user.data1 = (void*)event_info;
+    char* region;
+    app_event_get_region_format(event_info, &region);
+    event.user.data1 = (void*)region;
     event.user.data2 = (void*)user_data;
 
     SDL_PushEvent(&event);
@@ -157,7 +175,9 @@ _tizen_app_low_battery(app_event_info_h event_info, void *user_data)
     SDL_memset(&event, 0, sizeof(event));
     event.type = SDL_APP_LOWBATTERY;
     event.user.code = 0;
-    event.user.data1 = (void*)event_info;
+    app_event_low_battery_status_e status;
+    app_event_get_low_battery_status(event_info, &status);
+    event.user.data1 = (void*)status;
     event.user.data2 = (void*)user_data;
 
     SDL_PushEvent(&event);
@@ -217,12 +237,12 @@ SDL_tizen_app_init(int argc, char *argv[])
 
     if (tizen_appcore_initialized) {
         SDL_LogError(SDL_LOG_CATEGORY_ASSERT,"Already initialized!");
-        return 0;
+        return APP_ERROR_ALREADY_RUNNING;
     }
     tizen_appcore_initialized = 1;
     if (argc < 1 || argv == NULL) {
         SDL_LogError(SDL_LOG_CATEGORY_ASSERT,"APP_ERROR_INVALID_PARAMETER");
-        return 0;
+        return APP_ERROR_INVALID_PARAMETER;
     }
 
     event_callback.create = _tizen_sdl_create;
@@ -239,7 +259,7 @@ SDL_tizen_app_init(int argc, char *argv[])
     aul_ret = aul_add_status_local_cb(_tizen_aul_status_changed_cb, NULL);
     if (aul_ret == AUL_R_ERROR) {
         SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "AUL status changed callback setting is failed.");
-        return 0;
+        return APP_ERROR_INVALID_CONTEXT;
     }
 
     /* add event watch for SDL_APP_TERMINATING */