Skip to content

Commit

Permalink
Check for valid MPI_Comm before freeing
Browse files Browse the repository at this point in the history
If in parallel mode and the H5Fcreate fails, then the h5->comm field may/will point to MPI_COMM_NULL instead of to a valid communicator.  If that is passed to MPI_Comm_free, then the code will core dump down in the MPI_Comm_free function and not return a valid return status to the caller routine. If communicator is checked, then execution proceeds back up the call tree and caller can report a better error message about the failed file create.
  • Loading branch information
gsjaardema committed May 24, 2016
1 parent d88ad0e commit 4d037a1
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion libsrc4/nc4file.c
Original file line number Diff line number Diff line change
Expand Up @@ -3086,7 +3086,8 @@ close_netcdf4_file(NC_HDF5_FILE_INFO_T *h5, int abort)
/* Free the MPI Comm & Info objects, if we opened the file in parallel */
if(h5->parallel)
{
MPI_Comm_free(&h5->comm);
if(MPI_COMM_NULL != h5->comm)
MPI_Comm_free(&h5->comm);
if(MPI_INFO_NULL != h5->info)
MPI_Info_free(&h5->info);
}
Expand Down

0 comments on commit 4d037a1

Please sign in to comment.