@@ -80,6 +80,9 @@ ompio_io_ompio_file_open (ompi_communicator_t *comm,
8080 int remote_arch ;
8181
8282
83+ ompio_fh -> f_iov_type = MPI_DATATYPE_NULL ;
84+ ompio_fh -> f_comm = MPI_COMM_NULL ;
85+
8386 if ( ((amode & MPI_MODE_RDONLY )?1 :0 ) + ((amode & MPI_MODE_RDWR )?1 :0 ) +
8487 ((amode & MPI_MODE_WRONLY )?1 :0 ) != 1 ) {
8588 return MPI_ERR_AMODE ;
@@ -94,7 +97,6 @@ ompio_io_ompio_file_open (ompi_communicator_t *comm,
9497 return MPI_ERR_AMODE ;
9598 }
9699
97- ompio_fh -> f_iov_type = MPI_DATATYPE_NULL ;
98100 ompio_fh -> f_rank = ompi_comm_rank (comm );
99101 ompio_fh -> f_size = ompi_comm_size (comm );
100102 remote_arch = opal_local_arch ;
@@ -319,14 +321,27 @@ ompio_io_ompio_file_close (mca_io_ompio_file_t *ompio_fh)
319321 if ( NULL != ompio_fh -> f_sharedfp ){
320322 ret = ompio_fh -> f_sharedfp -> sharedfp_file_close (ompio_fh );
321323 }
322- ret = ompio_fh -> f_fs -> fs_file_close (ompio_fh );
324+ if ( NULL != ompio_fh -> f_fs ) {
325+ /* The pointer might not be set if file_close() is
326+ ** called from the file destructor in case of an error
327+ ** during file_open()
328+ */
329+ ret = ompio_fh -> f_fs -> fs_file_close (ompio_fh );
330+ }
323331 if ( delete_flag && 0 == ompio_fh -> f_rank ) {
324332 mca_io_ompio_file_delete ( ompio_fh -> f_filename , MPI_INFO_NULL );
325333 }
326334
327- mca_fs_base_file_unselect (ompio_fh );
328- mca_fbtl_base_file_unselect (ompio_fh );
329- mca_fcoll_base_file_unselect (ompio_fh );
335+ if ( NULL != ompio_fh -> f_fs ) {
336+ mca_fs_base_file_unselect (ompio_fh );
337+ }
338+ if ( NULL != ompio_fh -> f_fbtl ) {
339+ mca_fbtl_base_file_unselect (ompio_fh );
340+ }
341+
342+ if ( NULL != ompio_fh -> f_fcoll ) {
343+ mca_fcoll_base_file_unselect (ompio_fh );
344+ }
330345 if ( NULL != ompio_fh -> f_sharedfp ) {
331346 mca_sharedfp_base_file_unselect (ompio_fh );
332347 }
0 commit comments