From: Frederic Suter Date: Wed, 17 May 2017 10:55:47 +0000 (+0200) Subject: please sonar, less free in c++ X-Git-Tag: v3.16~281^2~16 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/da0d7d1fbe3beaa4a4b234bd39668700aec0031a?ds=sidebyside please sonar, less free in c++ --- diff --git a/src/msg/msg_global.cpp b/src/msg/msg_global.cpp index 0d94715ff6..a75e536279 100644 --- a/src/msg/msg_global.cpp +++ b/src/msg/msg_global.cpp @@ -38,7 +38,7 @@ void MSG_init_nocheck(int *argc, char **argv) { xbt_getpid = &MSG_process_self_PID; if (!msg_global) { - msg_global = xbt_new0(s_MSG_Global_t, 1); + msg_global = new s_MSG_Global_t(); xbt_cfg_register_boolean("msg/debug-multiple-use", "no", _sg_cfg_cb_msg_debug_multiple_use, "Print backtraces of both processes when there is a conflict of multiple use of a task"); @@ -121,7 +121,7 @@ static void MSG_exit() { TRACE_surf_resource_utilization_release(); TRACE_end(); - free(msg_global); + delete msg_global; msg_global = nullptr; } diff --git a/src/msg/msg_io.cpp b/src/msg/msg_io.cpp index 060e256413..702e0abc92 100644 --- a/src/msg/msg_io.cpp +++ b/src/msg/msg_io.cpp @@ -118,19 +118,15 @@ sg_size_t MSG_file_read(msg_file_t fd, sg_size_t size) if (strcmp(storage_priv_src->hostname, MSG_host_self()->cname())) { /* the file is hosted on a remote host, initiate a communication between src and dest hosts for data transfer */ XBT_DEBUG("File is on %s remote host, initiate data transfer of %llu bytes.", storage_priv_src->hostname, read_size); - msg_host_t *m_host_list = nullptr; - m_host_list = xbt_new0(msg_host_t, 2); - - m_host_list[0] = MSG_host_self(); - m_host_list[1] = attached_host; - double flops_amount[] = { 0, 0}; - double bytes_amount[] = { 0, 0, static_cast(read_size), 0 }; + msg_host_t m_host_list[] = {MSG_host_self(), attached_host}; + double flops_amount[] = {0, 0}; + double bytes_amount[] = {0, 0, static_cast(read_size), 0}; msg_task_t task = MSG_parallel_task_create("file transfer for read", 2, m_host_list, flops_amount, bytes_amount, nullptr); msg_error_t transfer = MSG_parallel_task_execute(task); MSG_task_destroy(task); - xbt_free(m_host_list); + if(transfer != MSG_OK){ if (transfer == MSG_HOST_FAILURE) XBT_WARN("Transfer error, %s remote host just turned off!", attached_host->cname()); @@ -163,19 +159,15 @@ sg_size_t MSG_file_write(msg_file_t fd, sg_size_t size) if (strcmp(storage_priv_src->hostname, MSG_host_self()->cname())) { /* the file is hosted on a remote host, initiate a communication between src and dest hosts for data transfer */ XBT_DEBUG("File is on %s remote host, initiate data transfer of %llu bytes.", storage_priv_src->hostname, size); - msg_host_t *m_host_list = nullptr; - m_host_list = xbt_new0(msg_host_t, 2); - - m_host_list[0] = MSG_host_self(); - m_host_list[1] = attached_host; - double flops_amount[] = { 0, 0 }; - double bytes_amount[] = { 0, static_cast(size), 0, 0 }; + msg_host_t m_host_list[] = {MSG_host_self(), attached_host}; + double flops_amount[] = {0, 0}; + double bytes_amount[] = {0, static_cast(size), 0, 0}; msg_task_t task = MSG_parallel_task_create("file transfer for write", 2, m_host_list, flops_amount, bytes_amount, nullptr); msg_error_t transfer = MSG_parallel_task_execute(task); MSG_task_destroy(task); - free(m_host_list); + if(transfer != MSG_OK){ if (transfer == MSG_HOST_FAILURE) XBT_WARN("Transfer error, %s remote host just turned off!", attached_host->cname()); @@ -332,14 +324,14 @@ msg_error_t MSG_file_rcopy (msg_file_t file, msg_host_t host, const char* fullpa char *mount_name; char *storage_name; xbt_dict_foreach(storage_list,cursor,mount_name,storage_name){ - char* file_mount_name = static_cast(xbt_malloc ((strlen(mount_name)+1))); - strncpy(file_mount_name,fullpath,strlen(mount_name)+1); + char* file_mount_name = static_cast(xbt_malloc(strlen(mount_name) + 1)); + strncpy(file_mount_name, fullpath, strlen(mount_name) + 1); file_mount_name[strlen(mount_name)] = '\0'; - if(!strcmp(file_mount_name,mount_name) && strlen(mount_name)>longest_prefix_length){ + if (!strcmp(file_mount_name, mount_name) && strlen(mount_name) > longest_prefix_length) { /* The current mount name is found in the full path and is bigger than the previous*/ longest_prefix_length = strlen(mount_name); - storage_dest = (msg_storage_t) xbt_lib_get_elm_or_null(storage_lib, storage_name); + storage_dest = (msg_storage_t)xbt_lib_get_elm_or_null(storage_lib, storage_name); } xbt_free(file_mount_name); } @@ -358,19 +350,15 @@ msg_error_t MSG_file_rcopy (msg_file_t file, msg_host_t host, const char* fullpa XBT_DEBUG("Initiate data transfer of %llu bytes between %s and %s.", read_size, storage_priv_src->hostname, host_name_dest); - msg_host_t *m_host_list = nullptr; - m_host_list = xbt_new0(msg_host_t, 2); - - m_host_list[0] = attached_host; - m_host_list[1] = host_dest; - double flops_amount[] = { 0, 0 }; - double bytes_amount[] = { 0, static_cast(read_size), 0, 0 }; + msg_host_t m_host_list[] = {attached_host, host_dest}; + double flops_amount[] = {0, 0}; + double bytes_amount[] = {0, static_cast(read_size), 0, 0}; msg_task_t task = MSG_parallel_task_create("file transfer for write", 2, m_host_list, flops_amount, bytes_amount, nullptr); msg_error_t transfer = MSG_parallel_task_execute(task); MSG_task_destroy(task); - xbt_free(m_host_list); + if(transfer != MSG_OK){ if (transfer == MSG_HOST_FAILURE) XBT_WARN("Transfer error, %s remote host just turned off!", host_name_dest); diff --git a/teshsuite/surf/maxmin_bench/maxmin_bench.cpp b/teshsuite/surf/maxmin_bench/maxmin_bench.cpp index bc5bbe5f7d..7d4323c5cf 100644 --- a/teshsuite/surf/maxmin_bench/maxmin_bench.cpp +++ b/teshsuite/surf/maxmin_bench/maxmin_bench.cpp @@ -38,9 +38,9 @@ static unsigned int int_random(int max) static void test(int nb_cnst, int nb_var, int nb_elem, unsigned int pw_base_limit, unsigned int pw_max_limit, float rate_no_limit, int max_share, int mode) { - lmm_constraint_t *cnst = xbt_new0(lmm_constraint_t, nb_cnst); - lmm_variable_t *var = xbt_new0(lmm_variable_t, nb_var); - int *used = xbt_new0(int, nb_cnst); + lmm_constraint_t cnst[nb_cnst]; + lmm_variable_t var[nb_var]; + int used[nb_cnst]; int concurrency_share; lmm_system_t Sys = lmm_system_new(1); @@ -106,9 +106,6 @@ static void test(int nb_cnst, int nb_var, int nb_elem, unsigned int pw_base_limi for (int i = 0; i < nb_var; i++) lmm_variable_free(Sys, var[i]); lmm_system_free(Sys); - free(cnst); - free(var); - free(used); } unsigned int TestClasses [][4]=