Skip to content

Commit b484784

Browse files
committed
make ompio return gracefully in case something goes wrong early in file_open.
1 parent 86c3000 commit b484784

File tree

2 files changed

+22
-7
lines changed

2 files changed

+22
-7
lines changed

ompi/mca/io/ompio/io_ompio_component.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
* University of Stuttgart. All rights reserved.
1111
* Copyright (c) 2004-2005 The Regents of the University of California.
1212
* All rights reserved.
13-
* Copyright (c) 2008-2014 University of Houston. All rights reserved.
13+
* Copyright (c) 2008-2015 University of Houston. All rights reserved.
1414
* Copyright (c) 2015 Los Alamos National Security, LLC. All rights
1515
* reserved.
1616
* Copyright (c) 2015 Research Organization for Information Science
@@ -257,7 +257,7 @@ file_query(struct ompi_file_t *file,
257257
/* Allocate a space for this module to hang private data (e.g.,
258258
the OMPIO file handle) */
259259

260-
data = malloc(sizeof(mca_io_ompio_data_t));
260+
data = calloc(1, sizeof(mca_io_ompio_data_t));
261261
if (NULL == data) {
262262
return NULL;
263263
}

ompi/mca/io/ompio/io_ompio_file_open.c

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)