Handle memory allocation failure 52/139452/2
authorSemun Lee <semun.lee@samsung.com>
Wed, 19 Jul 2017 04:37:22 +0000 (13:37 +0900)
committerSemun Lee <semun.lee@samsung.com>
Wed, 19 Jul 2017 05:39:01 +0000 (14:39 +0900)
Change-Id: Id4f0688bcf36d5045af165979b3270fa291af2fc

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

index 0a2c3b9..7a26034 100644 (file)
@@ -2150,6 +2150,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.");
@@ -2197,13 +2198,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 93626ec..efdc107 100644 (file)
@@ -1886,6 +1886,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;
@@ -1935,6 +1939,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);