Skip to content

Commit e59f58a

Browse files
authored
Merge pull request #5297 from edgargabriel/topic/sharedfp-revamp
sharedfp/sm and lockedfile: fix coverty warnings
2 parents cf48baf + c3ac06d commit e59f58a

File tree

2 files changed

+50
-13
lines changed

2 files changed

+50
-13
lines changed

ompi/mca/sharedfp/lockedfile/sharedfp_lockedfile_file_open.c

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,15 @@ int mca_sharedfp_lockedfile_file_open (struct ompi_communicator_t *comm,
7878
ompi_proc_t *masterproc = ompi_group_peer_lookup(comm->c_local_group, 0 );
7979
masterjobid = OMPI_CAST_RTE_NAME(&masterproc->super.proc_name)->jobid;
8080
}
81-
comm->c_coll->coll_bcast ( &masterjobid, 1, MPI_UNSIGNED, 0, comm,
82-
comm->c_coll->coll_bcast_module );
83-
81+
err = comm->c_coll->coll_bcast ( &masterjobid, 1, MPI_UNSIGNED, 0, comm,
82+
comm->c_coll->coll_bcast_module );
83+
if ( OMPI_SUCCESS != err ) {
84+
opal_output(0, "[%d]mca_sharedfp_lockedfile_file_open: Error in bcast operation\n", fh->f_rank);
85+
free (sh);
86+
free(module_data);
87+
return err;
88+
}
89+
8490
size_t filenamelen = strlen(filename) + 16;
8591
lockedfilename = (char*)malloc(sizeof(char) * filenamelen);
8692
if ( NULL == lockedfilename ) {
@@ -100,16 +106,33 @@ int mca_sharedfp_lockedfile_file_open (struct ompi_communicator_t *comm,
100106
*therefore there is no need to lock the file
101107
*/
102108
handle = open ( lockedfilename, O_RDWR | O_CREAT, 0644 );
109+
if ( -1 == handle ){
110+
opal_output(0, "[%d]mca_sharedfp_lockedfile_file_open: Error during file open\n",
111+
fh->f_rank);
112+
free (sh);
113+
free(module_data);
114+
free (lockedfilename);
115+
return OMPI_ERROR;
116+
}
103117
write ( handle, &position, sizeof(OMPI_MPI_OFFSET_TYPE) );
104118
close ( handle );
105119
}
106-
comm->c_coll->coll_barrier ( comm, comm->c_coll->coll_barrier_module );
120+
err = comm->c_coll->coll_barrier ( comm, comm->c_coll->coll_barrier_module );
121+
if ( OMPI_SUCCESS != err ) {
122+
opal_output(0, "[%d]mca_sharedfp_lockedfile_file_open: Error in barrier operation\n", fh->f_rank);
123+
free (sh);
124+
free(module_data);
125+
free (lockedfilename);
126+
return err;
127+
}
107128

108129
handle = open ( lockedfilename, O_RDWR, 0644 );
109130
if ( -1 == handle ) {
110-
opal_output(0, "[%d]mca_sharedfp_lockedfile_file_open: Error during file open\n", fh->f_rank);
131+
opal_output(0, "[%d]mca_sharedfp_lockedfile_file_open: Error during file open\n",
132+
fh->f_rank);
111133
free (sh);
112134
free(module_data);
135+
free (lockedfilename);
113136
return OMPI_ERROR;
114137
}
115138

@@ -120,9 +143,7 @@ int mca_sharedfp_lockedfile_file_open (struct ompi_communicator_t *comm,
120143
/*remember the shared file handle*/
121144
fh->f_sharedfp_data = sh;
122145

123-
comm->c_coll->coll_barrier ( comm, comm->c_coll->coll_barrier_module );
124-
125-
return err;
146+
return comm->c_coll->coll_barrier ( comm, comm->c_coll->coll_barrier_module );
126147
}
127148

128149
int mca_sharedfp_lockedfile_file_close (ompio_file_t *fh)

ompi/mca/sharedfp/sm/sharedfp_sm_file_open.c

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -126,12 +126,20 @@ int mca_sharedfp_sm_file_open (struct ompi_communicator_t *comm,
126126

127127
sm_data->sm_filename = sm_filename;
128128

129-
/*TODO: is it necessary to write to the file first?*/
129+
/* TODO: is it necessary to write to the file first? */
130130
if( 0 == fh->f_rank ){
131131
memset ( &sm_offset, 0, sizeof (struct mca_sharedfp_sm_offset ));
132132
write ( sm_fd, &sm_offset, sizeof(struct mca_sharedfp_sm_offset));
133133
}
134-
comm->c_coll->coll_barrier (comm, comm->c_coll->coll_barrier_module );
134+
err = comm->c_coll->coll_barrier (comm, comm->c_coll->coll_barrier_module );
135+
if ( OMPI_SUCCESS != err ) {
136+
opal_output(0,"mca_sharedfp_sm_file_open: Error in barrier operation \n");
137+
free(sm_filename);
138+
free(sm_data);
139+
free(sh);
140+
close (sm_fd);
141+
return err;
142+
}
135143

136144
/*the file has been written to, now we can map*/
137145
sm_offset_ptr = mmap(NULL, sizeof(struct mca_sharedfp_sm_offset), PROT_READ | PROT_WRITE,
@@ -188,18 +196,26 @@ int mca_sharedfp_sm_file_open (struct ompi_communicator_t *comm,
188196
free(sm_data);
189197
free(sh);
190198
munmap(sm_offset_ptr, sizeof(struct mca_sharedfp_sm_offset));
191-
err = OMPI_ERROR;
199+
return OMPI_ERROR;
192200
}
193201

194-
comm->c_coll->coll_barrier (comm, comm->c_coll->coll_barrier_module );
202+
err = comm->c_coll->coll_barrier (comm, comm->c_coll->coll_barrier_module );
203+
if ( OMPI_SUCCESS != err ) {
204+
opal_output(0,"mca_sharedfp_sm_file_open: Error in barrier operation \n");
205+
free(sm_filename);
206+
free(sm_data);
207+
free(sh);
208+
munmap(sm_offset_ptr, sizeof(struct mca_sharedfp_sm_offset));
209+
return err;
210+
}
195211

196212
#if defined(HAVE_SEM_OPEN)
197213
if ( 0 == fh->f_rank ) {
198214
sem_unlink ( sm_data->sem_name);
199215
}
200216
#endif
201217

202-
return err;
218+
return OMPI_SUCCESS;
203219
}
204220

205221
int mca_sharedfp_sm_file_close (ompio_file_t *fh)

0 commit comments

Comments
 (0)