@@ -109,6 +109,7 @@ int mca_sharedfp_sm_file_open (struct ompi_communicator_t *comm,
109109 sm_filename = (char * ) malloc ( sizeof (char ) * sm_filename_length );
110110 if (NULL == sm_filename ) {
111111 opal_output (0 , "mca_sharedfp_sm_file_open: Error, unable to malloc sm_filename\n" );
112+ free (filename_basename );
112113 free (sm_data );
113114 free (sh );
114115 return OMPI_ERR_OUT_OF_RESOURCE ;
@@ -122,6 +123,7 @@ int mca_sharedfp_sm_file_open (struct ompi_communicator_t *comm,
122123 err = comm -> c_coll -> coll_bcast (& int_pid , 1 , MPI_INT , 0 , comm , comm -> c_coll -> coll_bcast_module );
123124 if ( OMPI_SUCCESS != err ) {
124125 opal_output (0 ,"mca_sharedfp_sm_file_open: Error in bcast operation \n" );
126+ free (filename_basename );
125127 free (sm_filename );
126128 free (sm_data );
127129 free (sh );
@@ -136,6 +138,7 @@ int mca_sharedfp_sm_file_open (struct ompi_communicator_t *comm,
136138 if ( sm_fd == -1 ){
137139 /*error opening file*/
138140 opal_output (0 ,"mca_sharedfp_sm_file_open: Error, unable to open file for mmap: %s\n" ,sm_filename );
141+ free (filename_basename );
139142 free (sm_filename );
140143 free (sm_data );
141144 free (sh );
@@ -152,6 +155,7 @@ int mca_sharedfp_sm_file_open (struct ompi_communicator_t *comm,
152155 err = comm -> c_coll -> coll_barrier (comm , comm -> c_coll -> coll_barrier_module );
153156 if ( OMPI_SUCCESS != err ) {
154157 opal_output (0 ,"mca_sharedfp_sm_file_open: Error in barrier operation \n" );
158+ free (filename_basename );
155159 free (sm_filename );
156160 free (sm_data );
157161 free (sh );
@@ -169,6 +173,7 @@ int mca_sharedfp_sm_file_open (struct ompi_communicator_t *comm,
169173 err = OMPI_ERROR ;
170174 opal_output (0 , "mca_sharedfp_sm_file_open: Error, unable to mmap file: %s\n" ,sm_filename );
171175 opal_output (0 , "%s\n" , strerror (errno ));
176+ free (filename_basename );
172177 free (sm_filename );
173178 free (sm_data );
174179 free (sh );
@@ -187,6 +192,10 @@ int mca_sharedfp_sm_file_open (struct ompi_communicator_t *comm,
187192 sm_data -> sem_name = (char * ) malloc ( sizeof (char ) * 253 );
188193 snprintf (sm_data -> sem_name ,252 ,"OMPIO_%s" ,filename_basename );
189194#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 ;
190199
191200 if ( (sm_data -> mutex = sem_open (sm_data -> sem_name , O_CREAT , 0644 , 1 )) != SEM_FAILED ) {
192201#elif defined(HAVE_SEM_INIT)
0 commit comments