Handle memory allocation failure 42/143142/1 accepted/tizen_3.0_ivi accepted/tizen/3.0/common/20170810.115119 accepted/tizen/3.0/ivi/20170810.094455 accepted/tizen/3.0/mobile/20170810.094346 accepted/tizen/3.0/tv/20170810.094440 accepted/tizen/3.0/wearable/20170810.094402 submit/tizen_3.0/20170809.043616
authorSemun Lee <semun.lee@samsung.com>
Wed, 19 Jul 2017 04:37:22 +0000 (13:37 +0900)
committerjusung son <jusung07.son@samsung.com>
Wed, 9 Aug 2017 00:52:27 +0000 (00:52 +0000)
Change-Id: Id4f0688bcf36d5045af165979b3270fa291af2fc
(cherry picked from commit f1ef07d08f40495c8fc5de980dd76bb1a243bc28)

alarm-manager.c
src/alarm-lib.c

index b97ae04..8d6204e 100644 (file)
@@ -2100,6 +2100,7 @@ static int __on_app_uninstalled(uid_t target_uid, int req_id, const char *pkg_ty
 bool __get_caller_unique_name(int pid, char *unique_name, bool *is_app, uid_t uid)
 {
        char caller_appid[256] = {0,};
+       appid_cache_t* entry;
 
        if (unique_name == NULL) {
                ALARM_MGR_EXCEPTION_PRINT("unique_name should not be NULL.");
@@ -2147,13 +2148,15 @@ bool __get_caller_unique_name(int pid, char *unique_name, bool *is_app, uid_t ui
                        strncpy(unique_name, process_name, strlen(process_name));
                }
        }
-       appid_cache_t* entry = (appid_cache_t*)calloc(1, sizeof(appid_cache_t));
 
-       entry->unique_name = strdup(unique_name);
-       entry->is_app = is_app ? *is_app : false;
-       entry->pid = pid;
        g_hash_table_foreach_remove(appid_cache_table, __hash_table_remove_cb, (gpointer)unique_name);
-       g_hash_table_insert(appid_cache_table, &entry->pid, (gpointer)entry);
+       entry = (appid_cache_t*)calloc(1, sizeof(appid_cache_t));
+       if (entry) {
+               entry->unique_name = strdup(unique_name);
+               entry->is_app = is_app ? *is_app : false;
+               entry->pid = pid;
+               g_hash_table_insert(appid_cache_table, &entry->pid, (gpointer)entry);
+       }
 
        SECURE_LOGD("unique_name= %s", unique_name);
        return true;
index 01e7325..a883e44 100644 (file)
@@ -1880,6 +1880,10 @@ EXPORT_API int alarmmgr_set_systime_async(int new_time, alarm_set_time_cb_t resu
                g_type_init();
 #endif
                param = g_try_new0(struct alarm_async_param_t, 1);
+               if (param == NULL) {
+                       ALARM_MGR_EXCEPTION_PRINT("Failed to alloc param");
+                       return ERR_ALARM_SYSTEM_FAIL;
+               }
                param->type = SET_SYSTIME;
                param->v = g_variant_new("i", new_time);
                param->result_cb = result_cb;
@@ -1929,6 +1933,10 @@ EXPORT_API int alarmmgr_set_systime_with_propagation_delay_async(struct timespec
                g_type_init();
 #endif
                param = g_try_new0(struct alarm_async_param_t, 1);
+               if (param == NULL) {
+                       ALARM_MGR_EXCEPTION_PRINT("Failed to alloc param");
+                       return ERR_ALARM_SYSTEM_FAIL;
+               }
                param->type = SET_SYSTIME_WITH_PROPAGATION_DELAY;
                param->v = g_variant_new("(uuuu)", new_time.tv_sec, new_time.tv_nsec,
                                req_time.tv_sec, req_time.tv_nsec);