@@ -109,6 +109,7 @@ int mca_sharedfp_sm_file_open (struct ompi_communicator_t *comm,
109
109
sm_filename = (char * ) malloc ( sizeof (char ) * sm_filename_length );
110
110
if (NULL == sm_filename ) {
111
111
opal_output (0 , "mca_sharedfp_sm_file_open: Error, unable to malloc sm_filename\n" );
112
+ free (filename_basename );
112
113
free (sm_data );
113
114
free (sh );
114
115
return OMPI_ERR_OUT_OF_RESOURCE ;
@@ -122,6 +123,7 @@ int mca_sharedfp_sm_file_open (struct ompi_communicator_t *comm,
122
123
err = comm -> c_coll -> coll_bcast (& int_pid , 1 , MPI_INT , 0 , comm , comm -> c_coll -> coll_bcast_module );
123
124
if ( OMPI_SUCCESS != err ) {
124
125
opal_output (0 ,"mca_sharedfp_sm_file_open: Error in bcast operation \n" );
126
+ free (filename_basename );
125
127
free (sm_filename );
126
128
free (sm_data );
127
129
free (sh );
@@ -136,6 +138,7 @@ int mca_sharedfp_sm_file_open (struct ompi_communicator_t *comm,
136
138
if ( sm_fd == -1 ){
137
139
/*error opening file*/
138
140
opal_output (0 ,"mca_sharedfp_sm_file_open: Error, unable to open file for mmap: %s\n" ,sm_filename );
141
+ free (filename_basename );
139
142
free (sm_filename );
140
143
free (sm_data );
141
144
free (sh );
@@ -152,6 +155,7 @@ int mca_sharedfp_sm_file_open (struct ompi_communicator_t *comm,
152
155
err = comm -> c_coll -> coll_barrier (comm , comm -> c_coll -> coll_barrier_module );
153
156
if ( OMPI_SUCCESS != err ) {
154
157
opal_output (0 ,"mca_sharedfp_sm_file_open: Error in barrier operation \n" );
158
+ free (filename_basename );
155
159
free (sm_filename );
156
160
free (sm_data );
157
161
free (sh );
@@ -169,6 +173,7 @@ int mca_sharedfp_sm_file_open (struct ompi_communicator_t *comm,
169
173
err = OMPI_ERROR ;
170
174
opal_output (0 , "mca_sharedfp_sm_file_open: Error, unable to mmap file: %s\n" ,sm_filename );
171
175
opal_output (0 , "%s\n" , strerror (errno ));
176
+ free (filename_basename );
172
177
free (sm_filename );
173
178
free (sm_data );
174
179
free (sh );
@@ -187,6 +192,10 @@ int mca_sharedfp_sm_file_open (struct ompi_communicator_t *comm,
187
192
sm_data -> sem_name = (char * ) malloc ( sizeof (char ) * 253 );
188
193
snprintf (sm_data -> sem_name ,252 ,"OMPIO_%s" ,filename_basename );
189
194
#endif
195
+ // We're now done with filename_basename. Free it here so that we
196
+ // don't have to keep freeing it in the error/return cases.
197
+ free (filename_basename );
198
+ filename_basename = NULL ;
190
199
191
200
if ( (sm_data -> mutex = sem_open (sm_data -> sem_name , O_CREAT , 0644 , 1 )) != SEM_FAILED ) {
192
201
#elif defined(HAVE_SEM_INIT)
0 commit comments