Skip to content

Commit 0398598

Browse files
committed
sharedfp: fix minor memory leaks
Commit c79291e accidentally introduced minor memory leaks by calling opal_basename() without free()ing the results. Fixes CID 1496830. Signed-off-by: Jeff Squyres <jsquyres@cisco.com>
1 parent ecdd746 commit 0398598

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

ompi/mca/sharedfp/sm/sharedfp_sm.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ struct mca_sharedfp_base_module_1_0_0_t * mca_sharedfp_sm_component_file_query(o
107107

108108
asprintf(&sm_filename, "%s/%s_cid-%d-%d.sm", ompi_process_info.job_session_dir,
109109
filename_basename, comm_cid, pid);
110+
free(filename_basename);
110111

111112
int sm_fd = open(sm_filename, O_RDWR | O_CREAT,
112113
S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);

ompi/mca/sharedfp/sm/sharedfp_sm_file_open.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)