Skip to content

Commit 2118615

Browse files
committed
file.c: fix uninitialized mutex in MPI_File handle
We were initializing the mutex in file_open, but that didn't handle MPI_FILE_NULL. So we move it to the constructor, and therefore it's always initialized for all file handles -- even MPI_FILE_NULL. Signed-off-by: George Bosilca <[email protected]> Signed-off-by: Jeff Squyres <[email protected]>
1 parent 42e1cd8 commit 2118615

File tree

1 file changed

+3
-6
lines changed

1 file changed

+3
-6
lines changed

ompi/file/file.c

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -131,9 +131,6 @@ int ompi_file_open(struct ompi_communicator_t *comm, const char *filename,
131131
return OMPI_ERR_OUT_OF_RESOURCE;
132132
}
133133

134-
/* Create the mutex */
135-
OBJ_CONSTRUCT(&file->f_lock, opal_mutex_t);
136-
137134
/* Select a module and actually open the file */
138135

139136
if (OMPI_SUCCESS != (ret = mca_io_base_file_select(file, NULL))) {
@@ -156,9 +153,6 @@ int ompi_file_open(struct ompi_communicator_t *comm, const char *filename,
156153
*/
157154
int ompi_file_close(ompi_file_t **file)
158155
{
159-
160-
OBJ_DESTRUCT(&(*file)->f_lock);
161-
162156
(*file)->f_flags |= OMPI_FILE_ISCLOSED;
163157
OBJ_RELEASE(*file);
164158
*file = &ompi_mpi_file_null.file;
@@ -241,6 +235,7 @@ static void file_constructor(ompi_file_t *file)
241235
file->f_comm = NULL;
242236
file->f_filename = NULL;
243237
file->f_amode = 0;
238+
OBJ_CONSTRUCT(&file->f_lock, opal_mutex_t);
244239

245240
/* Initialize flags */
246241

@@ -335,4 +330,6 @@ static void file_destructor(ompi_file_t *file)
335330
opal_pointer_array_set_item(&ompi_file_f_to_c_table,
336331
file->f_f_to_c_index, NULL);
337332
}
333+
334+
OBJ_DESTRUCT(&(file->f_lock));
338335
}

0 commit comments

Comments
 (0)