9
9
* University of Stuttgart. All rights reserved.
10
10
* Copyright (c) 2004-2005 The Regents of the University of California.
11
11
* All rights reserved.
12
- * Copyright (c) 2013-2018 University of Houston. All rights reserved.
12
+ * Copyright (c) 2013-2021 University of Houston. All rights reserved.
13
13
* Copyright (c) 2013 Intel, Inc. All rights reserved.
14
14
* Copyright (c) 2015-2018 Research Organization for Information Science
15
15
* and Technology (RIST). All rights reserved.
16
- * Copyright (c) 2015 Cisco Systems, Inc. All rights reserved.
16
+ * Copyright (c) 2015-2021 Cisco Systems, Inc. All rights reserved.
17
17
* Copyright (c) 2016-2017 IBM Corporation. All rights reserved.
18
18
* $COPYRIGHT$
19
19
*
41
41
#include "ompi/mca/sharedfp/sharedfp.h"
42
42
#include "ompi/mca/sharedfp/base/base.h"
43
43
44
+ #include "opal/util/basename.h"
45
+
44
46
#include <semaphore.h>
45
47
#include <sys/mman.h>
46
48
#include <libgen.h>
@@ -57,7 +59,6 @@ int mca_sharedfp_sm_file_open (struct ompi_communicator_t *comm,
57
59
struct mca_sharedfp_sm_data * sm_data = NULL ;
58
60
char * filename_basename ;
59
61
char * sm_filename ;
60
- int sm_filename_length ;
61
62
struct mca_sharedfp_sm_offset * sm_offset_ptr ;
62
63
struct mca_sharedfp_sm_offset sm_offset ;
63
64
int sm_fd ;
@@ -101,16 +102,8 @@ int mca_sharedfp_sm_file_open (struct ompi_communicator_t *comm,
101
102
** and then mapping it to memory
102
103
** For sharedfp we also want to put the file backed shared memory into the tmp directory
103
104
*/
104
- filename_basename = basename ((char * )filename );
105
+ filename_basename = opal_basename ((char * )filename );
105
106
/* format is "%s/%s_cid-%d-%d.sm", see below */
106
- sm_filename_length = strlen (ompi_process_info .job_session_dir ) + 1 + strlen (filename_basename ) + 5 + (3 * sizeof (uint32_t )+1 ) + 4 ;
107
- sm_filename = (char * ) malloc ( sizeof (char ) * sm_filename_length );
108
- if (NULL == sm_filename ) {
109
- opal_output (0 , "mca_sharedfp_sm_file_open: Error, unable to malloc sm_filename\n" );
110
- free (sm_data );
111
- free (sh );
112
- return OMPI_ERR_OUT_OF_RESOURCE ;
113
- }
114
107
115
108
comm_cid = ompi_comm_get_cid (comm );
116
109
if ( 0 == fh -> f_rank ) {
@@ -120,20 +113,21 @@ int mca_sharedfp_sm_file_open (struct ompi_communicator_t *comm,
120
113
err = comm -> c_coll -> coll_bcast (& int_pid , 1 , MPI_INT , 0 , comm , comm -> c_coll -> coll_bcast_module );
121
114
if ( OMPI_SUCCESS != err ) {
122
115
opal_output (0 ,"mca_sharedfp_sm_file_open: Error in bcast operation \n" );
123
- free (sm_filename );
116
+ free (filename_basename );
124
117
free (sm_data );
125
118
free (sh );
126
119
return err ;
127
120
}
128
121
129
- snprintf ( sm_filename , sm_filename_length , "%s/%s_cid-%d-%d.sm" , ompi_process_info .job_session_dir ,
122
+ asprintf ( & sm_filename , "%s/%s_cid-%d-%d.sm" , ompi_process_info .job_session_dir ,
130
123
filename_basename , comm_cid , int_pid );
131
124
/* open shared memory file, initialize to 0, map into memory */
132
125
sm_fd = open (sm_filename , O_RDWR | O_CREAT ,
133
126
S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH );
134
127
if ( sm_fd == -1 ){
135
128
/*error opening file*/
136
129
opal_output (0 ,"mca_sharedfp_sm_file_open: Error, unable to open file for mmap: %s\n" ,sm_filename );
130
+ free (filename_basename );
137
131
free (sm_filename );
138
132
free (sm_data );
139
133
free (sh );
@@ -150,6 +144,7 @@ int mca_sharedfp_sm_file_open (struct ompi_communicator_t *comm,
150
144
err = comm -> c_coll -> coll_barrier (comm , comm -> c_coll -> coll_barrier_module );
151
145
if ( OMPI_SUCCESS != err ) {
152
146
opal_output (0 ,"mca_sharedfp_sm_file_open: Error in barrier operation \n" );
147
+ free (filename_basename );
153
148
free (sm_filename );
154
149
free (sm_data );
155
150
free (sh );
@@ -167,6 +162,7 @@ int mca_sharedfp_sm_file_open (struct ompi_communicator_t *comm,
167
162
err = OMPI_ERROR ;
168
163
opal_output (0 , "mca_sharedfp_sm_file_open: Error, unable to mmap file: %s\n" ,sm_filename );
169
164
opal_output (0 , "%s\n" , strerror (errno ));
165
+ free (filename_basename );
170
166
free (sm_filename );
171
167
free (sm_data );
172
168
free (sh );
@@ -185,6 +181,10 @@ int mca_sharedfp_sm_file_open (struct ompi_communicator_t *comm,
185
181
sm_data -> sem_name = (char * ) malloc ( sizeof (char ) * 253 );
186
182
snprintf (sm_data -> sem_name ,252 ,"OMPIO_%s" ,filename_basename );
187
183
#endif
184
+ // We're now done with filename_basename. Free it here so that we
185
+ // don't have to keep freeing it in the error/return cases.
186
+ free (filename_basename );
187
+ filename_basename = NULL ;
188
188
189
189
if ( (sm_data -> mutex = sem_open (sm_data -> sem_name , O_CREAT , 0644 , 1 )) != SEM_FAILED ) {
190
190
#elif defined(HAVE_SEM_INIT)
0 commit comments