diff --git a/ompi/mca/sharedfp/individual/sharedfp_individual_file_open.c b/ompi/mca/sharedfp/individual/sharedfp_individual_file_open.c index 4dd8a53947..d28f5f7b83 100644 --- a/ompi/mca/sharedfp/individual/sharedfp_individual_file_open.c +++ b/ompi/mca/sharedfp/individual/sharedfp_individual_file_open.c @@ -60,6 +60,7 @@ int mca_sharedfp_individual_file_open (struct ompi_communicator_t *comm, if ( NULL == sh ){ opal_output(0, "mca_sharedfp_individual_file_open: Error, unable to malloc " "f_sharedfp_ptr struct\n"); + free (shfileHandle ); return OMPI_ERR_OUT_OF_RESOURCE; } @@ -94,6 +95,8 @@ int mca_sharedfp_individual_file_open (struct ompi_communicator_t *comm, MPI_INFO_NULL, datafilehandle, false); if ( OMPI_SUCCESS != err) { opal_output(0, "mca_sharedfp_individual_file_open: Error during datafile file open\n"); + free (shfileHandle ); + free (sh); return err; } @@ -107,14 +110,31 @@ int mca_sharedfp_individual_file_open (struct ompi_communicator_t *comm, /* metadata filename created by appending .metadata.$rank to the original filename*/ metadatafilename = (char*) malloc ( len ); + if ( NULL == metadatafilename ) { + free (shfileHandle ); + free (sh); + opal_output(0, "mca_sharedfp_individual_file_open: Error during memory allocation\n"); + return OMPI_ERR_OUT_OF_RESOURCE; + } snprintf ( metadatafilename, len, "%s%s%d", filename, ".metadata.",rank); metadatafilehandle = (mca_io_ompio_file_t *)malloc(sizeof(mca_io_ompio_file_t)); + if ( NULL == metadatafilehandle ) { + free (shfileHandle ); + free (sh); + free (metadatafilename); + opal_output(0, "mca_sharedfp_individual_file_open: Error during memory allocation\n"); + return OMPI_ERR_OUT_OF_RESOURCE; + } err = ompio_io_ompio_file_open ( MPI_COMM_SELF,metadatafilename, MPI_MODE_RDWR | MPI_MODE_CREATE | MPI_MODE_DELETE_ON_CLOSE, MPI_INFO_NULL, metadatafilehandle, false); if ( OMPI_SUCCESS != err) { opal_output(0, "mca_sharedfp_individual_file_open: Error during metadatafile file open\n"); + free (shfileHandle ); + free (sh); + free (metadatafilename); + free (metadatafilehandle); return err; } diff --git a/ompi/mca/sharedfp/lockedfile/sharedfp_lockedfile_file_open.c b/ompi/mca/sharedfp/lockedfile/sharedfp_lockedfile_file_open.c index 6c44483691..a58e7851a6 100644 --- a/ompi/mca/sharedfp/lockedfile/sharedfp_lockedfile_file_open.c +++ b/ompi/mca/sharedfp/lockedfile/sharedfp_lockedfile_file_open.c @@ -61,6 +61,7 @@ int mca_sharedfp_lockedfile_file_open (struct ompi_communicator_t *comm, sh = (struct mca_sharedfp_base_data_t*)malloc(sizeof(struct mca_sharedfp_base_data_t)); if ( NULL == sh){ opal_output(0, "mca_sharedfp_lockedfile_file_open: Error, unable to malloc f_sharedfp_ptr struct\n"); + free ( shfileHandle); return OMPI_ERR_OUT_OF_RESOURCE; } /*Populate the sh file structure based on the implementation*/ @@ -80,6 +81,8 @@ int mca_sharedfp_lockedfile_file_open (struct ompi_communicator_t *comm, module_data = (struct mca_sharedfp_lockedfile_data*)malloc(sizeof(struct mca_sharedfp_lockedfile_data)); if ( NULL == module_data ) { printf("mca_sharedfp_lockedfile_file_open: Error, unable to malloc lockedfile_data struct\n"); + free (shfileHandle); + free (sh); return OMPI_ERR_OUT_OF_RESOURCE; } @@ -104,6 +107,8 @@ int mca_sharedfp_lockedfile_file_open (struct ompi_communicator_t *comm, handle = open ( lockedfilename, O_RDWR, 0644 ); if ( -1 == handle ) { printf("[%d]mca_sharedfp_lockedfile_file_open: Error during file open\n", rank); + free (shfileHandle); + free (sh); free(module_data); return OMPI_ERROR; } diff --git a/ompi/mca/sharedfp/sm/sharedfp_sm_file_open.c b/ompi/mca/sharedfp/sm/sharedfp_sm_file_open.c index 7cd3fdd5af..c3ef36149d 100644 --- a/ompi/mca/sharedfp/sm/sharedfp_sm_file_open.c +++ b/ompi/mca/sharedfp/sm/sharedfp_sm_file_open.c @@ -64,9 +64,14 @@ int mca_sharedfp_sm_file_open (struct ompi_communicator_t *comm, /*Open the same file again without shared file pointer*/ /*----------------------------------------------------*/ shfileHandle = (mca_io_ompio_file_t *)malloc(sizeof(mca_io_ompio_file_t)); + if ( NULL == shfileHandle ) { + opal_output(0, "mca_sharedfp_sm_file_open: Error during memory allocation\n"); + return OMPI_ERR_OUT_OF_RESOURCE; + } err = ompio_io_ompio_file_open(comm,filename,amode,info,shfileHandle,false); if ( OMPI_SUCCESS != err) { opal_output(0, "mca_sharedfp_sm_file_open: Error during file open\n"); + free (shfileHandle); return err; } shfileHandle->f_fh = fh->f_fh;