From 5b6af9bc65ee30c85ec25ea4b1da0711b2331f22 Mon Sep 17 00:00:00 2001 From: Inkyun Kil Date: Tue, 8 Aug 2017 13:44:46 +0900 Subject: Add null check when allocating memory Change-Id: Ifab866eb78db789af35748b753e9686b7739e1a0 Signed-off-by: Inkyun Kil --- src/data-control-internal.c | 7 ++++++- src/data-control-map.c | 5 +++++ src/data-control-noti.c | 5 +++++ src/data-control-provider.c | 12 ++++++++++++ src/data-control-sql.c | 9 +++++++++ 5 files changed, 37 insertions(+), 1 deletion(-) diff --git a/src/data-control-internal.c b/src/data-control-internal.c index 9701758..316bd59 100755 --- a/src/data-control-internal.c +++ b/src/data-control-internal.c @@ -624,11 +624,16 @@ char *_get_encoded_path(datacontrol_h provider, char *consumer_appid) encoded_path = g_compute_checksum_for_string(G_CHECKSUM_MD5, path, -1); full_path = (char *)calloc(full_path_len, sizeof(char)); + if (full_path == NULL) { + LOGE("Out of memory"); + goto out; + } snprintf(full_path, full_path_len, "%s%s", DATA_CONTROL_DBUS_PATH_PREFIX, encoded_path); + LOGI("full path : %s ", full_path); +out: free(path); free(encoded_path); - LOGI("full path : %s ", full_path); return full_path; } diff --git a/src/data-control-map.c b/src/data-control-map.c index b5239cf..296d854 100755 --- a/src/data-control-map.c +++ b/src/data-control-map.c @@ -521,6 +521,11 @@ static int __map_request_provider(datacontrol_h provider, datacontrol_request_ty map_response_cb_s *map_dc = *(map_response_cb_s **)map_dc_returned; app_id = map_dc->app_id; datacontrol_consumer_request_info *request_info = (datacontrol_consumer_request_info *)calloc(sizeof(datacontrol_consumer_request_info), 1); + if (request_info == NULL) { + LOGE("Out of memory"); + return DATACONTROL_ERROR_OUT_OF_MEMORY; + } + request_info->request_id = request_id; request_info->type = type; map_dc->request_info_list = g_list_append(map_dc->request_info_list, request_info); diff --git a/src/data-control-noti.c b/src/data-control-noti.c index 53541d9..fc34dae 100755 --- a/src/data-control-noti.c +++ b/src/data-control-noti.c @@ -405,6 +405,11 @@ int datacontrol_add_data_change_cb(datacontrol_h provider, result_cb_info = (add_callback_result_cb_info_s *)calloc(1, sizeof(add_callback_result_cb_info_s)); + if (result_cb_info == NULL) { + LOGE("Out of memory."); + ret = DATACONTROL_ERROR_OUT_OF_MEMORY; + goto err; + } result_cb_info->callback_id = *callback_id; result_cb_info->callback = result_callback; result_cb_info->user_data = result_cb_user_data; diff --git a/src/data-control-provider.c b/src/data-control-provider.c index dda6785..154f208 100755 --- a/src/data-control-provider.c +++ b/src/data-control-provider.c @@ -1013,6 +1013,10 @@ static int __init_changed_noti_consumer_list() consumer_info = (datacontrol_consumer_info *) calloc(1, sizeof(datacontrol_consumer_info)); + if (consumer_info == NULL) { + LOGE("Out of memory"); + continue; + } consumer_info->appid = strdup(app_id); consumer_info->object_path = strdup(object_path); consumer_info->unique_id = strdup(unique_id); @@ -1103,6 +1107,10 @@ static int __set_consumer_app_list( if (!find_list) { consumer_info = (datacontrol_consumer_info *) calloc(1, sizeof(datacontrol_consumer_info)); + if (consumer_info == NULL) { + LOGE("Out of memory"); + return DATACONTROL_ERROR_OUT_OF_MEMORY; + } consumer_info->appid = strdup(caller); consumer_info->object_path = strdup(object_path); consumer_info->unique_id = strdup(unique_id); @@ -2184,6 +2192,10 @@ int datacontrol_provider_add_data_change_consumer_filter_cb( { changed_noti_consumer_filter_info_s *filter_info = (changed_noti_consumer_filter_info_s *)calloc(1, sizeof(changed_noti_consumer_filter_info_s)); + if (filter_info == NULL) { + LOGE("Out of memory"); + return DATACONTROL_ERROR_IO_ERROR; + } *callback_id = _datacontrol_get_data_changed_filter_callback_id(); diff --git a/src/data-control-sql.c b/src/data-control-sql.c index cce6e53..8a5f237 100755 --- a/src/data-control-sql.c +++ b/src/data-control-sql.c @@ -888,6 +888,10 @@ static int __sql_request_provider(datacontrol_h provider, datacontrol_request_ty app_id = sql_dc->app_id; datacontrol_consumer_request_info *request_info = (datacontrol_consumer_request_info *)calloc(sizeof(datacontrol_consumer_request_info), 1); + if (request_info == NULL) { + LOGE("Out of memory"); + return DATACONTROL_ERROR_OUT_OF_MEMORY; + } request_info->request_id = request_id; request_info->type = type; sql_dc->request_info_list = g_list_append(sql_dc->request_info_list, request_info); @@ -1352,6 +1356,11 @@ int datacontrol_sql_select_with_page(datacontrol_h provider, char **column_list, total_arg_count = column_count + DATACONTROL_SELECT_EXTRA_COUNT; arg_list = (const char **)malloc(total_arg_count * (sizeof(char *))); + if (arg_list == NULL) { + LOGE("Out of memory"); + bundle_free(b); + return DATACONTROL_ERROR_OUT_OF_MEMORY; + } LOGI("total arg count %d", total_arg_count); -- cgit v1.2.3