diff --git a/ompi/mca/fcoll/static/fcoll_static_file_read_all.c b/ompi/mca/fcoll/static/fcoll_static_file_read_all.c index 17206628c3..7dfc62b66a 100644 --- a/ompi/mca/fcoll/static/fcoll_static_file_read_all.c +++ b/ompi/mca/fcoll/static/fcoll_static_file_read_all.c @@ -275,14 +275,14 @@ mca_fcoll_static_file_read_all (mca_io_ompio_file_t *fh, } - iovec_count_per_process = (int *) malloc (fh->f_procs_per_group * sizeof(int)); + iovec_count_per_process = (int *) calloc (fh->f_procs_per_group, sizeof(int)); if (NULL == iovec_count_per_process){ opal_output (1, "OUT OF MEMORY\n"); ret = OMPI_ERR_OUT_OF_RESOURCE; goto exit; } - displs = (int *) malloc (fh->f_procs_per_group * sizeof(int)); + displs = (int *) calloc (fh->f_procs_per_group, sizeof(int)); if (NULL == displs){ opal_output (1, "OUT OF MEMORY\n"); ret = OMPI_ERR_OUT_OF_RESOURCE; diff --git a/ompi/mca/fcoll/static/fcoll_static_file_write_all.c b/ompi/mca/fcoll/static/fcoll_static_file_write_all.c index 9e817b9dac..63265472c7 100644 --- a/ompi/mca/fcoll/static/fcoll_static_file_write_all.c +++ b/ompi/mca/fcoll/static/fcoll_static_file_write_all.c @@ -278,14 +278,14 @@ mca_fcoll_static_file_write_all (mca_io_ompio_file_t *fh, } } - iovec_count_per_process = (int *) malloc (fh->f_procs_per_group * sizeof(int)); + iovec_count_per_process = (int *) calloc (fh->f_procs_per_group, sizeof(int)); if (NULL == iovec_count_per_process){ opal_output (1, "OUT OF MEMORY\n"); ret = OMPI_ERR_OUT_OF_RESOURCE; goto exit; } - displs = (int *) malloc (fh->f_procs_per_group * sizeof(int)); + displs = (int *) calloc (fh->f_procs_per_group, sizeof(int)); if (NULL == displs){ opal_output (1, "OUT OF MEMORY\n"); ret = OMPI_ERR_OUT_OF_RESOURCE; @@ -1050,6 +1050,11 @@ exit: sorted = NULL; } + if (NULL != displs) { + free(displs); + displs = NULL; + } + return ret; } diff --git a/ompi/mca/io/ompio/io_ompio.c b/ompi/mca/io/ompio/io_ompio.c index 5ec6d9c594..dedebc58e9 100644 --- a/ompi/mca/io/ompio/io_ompio.c +++ b/ompi/mca/io/ompio/io_ompio.c @@ -1864,7 +1864,7 @@ int mca_io_ompio_merge_groups(mca_io_ompio_file_t *fh, { int i = 0; int *sizes_old_group; - + int ret = OMPI_SUCCESS; int *displs; @@ -1886,17 +1886,22 @@ int mca_io_ompio_merge_groups(mca_io_ompio_file_t *fh, //merge_aggrs[0] is considered the new aggregator //New aggregator collects group sizes of the groups to be merged - fcoll_base_coll_allgather_array (&fh->f_init_procs_per_group, - 1, - MPI_INT, - sizes_old_group, - 1, - MPI_INT, - 0, - merge_aggrs, - num_merge_aggrs, - fh->f_comm); + ret = fcoll_base_coll_allgather_array (&fh->f_init_procs_per_group, + 1, + MPI_INT, + sizes_old_group, + 1, + MPI_INT, + 0, + merge_aggrs, + num_merge_aggrs, + fh->f_comm); + if ( OMPI_SUCCESS != ret ) { + free (displs); + free (sizes_old_group); + return ret; + } fh->f_procs_per_group = 0; @@ -1920,23 +1925,22 @@ int mca_io_ompio_merge_groups(mca_io_ompio_file_t *fh, //New aggregator also collects the grouping distribution //This is the actual merge //use allgatherv array - fcoll_base_coll_allgatherv_array (fh->f_init_procs_in_group, - fh->f_init_procs_per_group, - MPI_INT, - fh->f_procs_in_group, - sizes_old_group, - displs, - MPI_INT, - 0, - merge_aggrs, - num_merge_aggrs, - fh->f_comm); + ret = fcoll_base_coll_allgatherv_array (fh->f_init_procs_in_group, + fh->f_init_procs_per_group, + MPI_INT, + fh->f_procs_in_group, + sizes_old_group, + displs, + MPI_INT, + 0, + merge_aggrs, + num_merge_aggrs, + fh->f_comm); - - free(displs); + free (displs); free (sizes_old_group); - return OMPI_SUCCESS; + return ret; }