Skip to content

Commit

Permalink
sc_io: free file context on sc_io_open error
Browse files Browse the repository at this point in the history
  • Loading branch information
cburstedde committed Nov 17, 2023
1 parent 60c61f7 commit 75dc397
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/sc_io.c
Original file line number Diff line number Diff line change
Expand Up @@ -1435,12 +1435,19 @@ sc_io_open (sc_MPI_Comm mpicomm, const char *filename,
(*mpifile)->file = sc_MPI_FILE_NULL;
mpiret = sc_MPI_SUCCESS;
}

/* broadcast errno */
sc_MPI_Bcast (&mpiret, 1, sc_MPI_INT, 0, mpicomm);

retval = sc_io_error_class (mpiret, &errcode);
SC_CHECK_MPI (retval);

/* free file structure on open error */
if (errcode != sc_MPI_SUCCESS) {
SC_FREE (*mpifile);
*mpifile = sc_MPI_FILE_NULL;
}

return errcode;
}
#else /* no MPI */
Expand All @@ -1460,6 +1467,12 @@ sc_io_open (sc_MPI_Comm mpicomm, const char *filename,
retval = sc_io_error_class (errno, &errcode);
SC_CHECK_MPI (retval);

/* free file structure on open error */
if (errcode != sc_MPI_SUCCESS) {
SC_FREE (*mpifile);
*mpifile = sc_MPI_FILE_NULL;
}

return errcode;
}
#endif
Expand Down

0 comments on commit 75dc397

Please sign in to comment.