Skip to content

Commit 634f67b

Browse files
authored
Merge pull request #7843 from devreal/clang-tidy-free
Some fixups for issues detected by clang-tidy
2 parents 907f4e1 + 602f833 commit 634f67b

File tree

11 files changed

+82
-38
lines changed

11 files changed

+82
-38
lines changed

ompi/attribute/attribute.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -979,6 +979,7 @@ int ompi_attr_copy_all(ompi_attribute_type_t type, void *old_object,
979979
/* Did the callback return non-MPI_SUCCESS? */
980980
if (0 != err) {
981981
ret = err;
982+
OBJ_RELEASE(new_attr);
982983
goto out;
983984
}
984985

ompi/mca/coll/base/coll_base_allgather.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -178,19 +178,19 @@ int ompi_coll_base_allgather_intra_bruck(const void *sbuf, int scount,
178178
/* 1. copy blocks [0 .. (size - rank - 1)] from rbuf to shift buffer */
179179
err = ompi_datatype_copy_content_same_ddt(rdtype, ((ptrdiff_t)(size - rank) * (ptrdiff_t)rcount),
180180
shift_buf, rbuf);
181-
if (err < 0) { line = __LINE__; goto err_hndl; }
181+
if (err < 0) { line = __LINE__; free(free_buf); goto err_hndl; }
182182

183183
/* 2. move blocks [(size - rank) .. size] from rbuf to the begining of rbuf */
184184
tmpsend = (char*) rbuf + (ptrdiff_t)(size - rank) * (ptrdiff_t)rcount * rext;
185185
err = ompi_datatype_copy_content_same_ddt(rdtype, (ptrdiff_t)rank * (ptrdiff_t)rcount,
186186
rbuf, tmpsend);
187-
if (err < 0) { line = __LINE__; goto err_hndl; }
187+
if (err < 0) { line = __LINE__; free(free_buf); goto err_hndl; }
188188

189189
/* 3. copy blocks from shift buffer back to rbuf starting at block [rank]. */
190190
tmprecv = (char*) rbuf + (ptrdiff_t)rank * (ptrdiff_t)rcount * rext;
191191
err = ompi_datatype_copy_content_same_ddt(rdtype, (ptrdiff_t)(size - rank) * (ptrdiff_t)rcount,
192192
tmprecv, shift_buf);
193-
if (err < 0) { line = __LINE__; goto err_hndl; }
193+
if (err < 0) { line = __LINE__; free(free_buf); goto err_hndl; }
194194

195195
free(free_buf);
196196
}

ompi/mca/coll/base/coll_base_reduce.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -688,6 +688,9 @@ ompi_coll_base_reduce_intra_basic_linear(const void *sbuf, void *rbuf, int count
688688
if (NULL != free_buffer) {
689689
free(free_buffer);
690690
}
691+
if (NULL != inplace_temp_free) {
692+
free(inplace_temp_free);
693+
}
691694
return err;
692695
}
693696

@@ -704,6 +707,9 @@ ompi_coll_base_reduce_intra_basic_linear(const void *sbuf, void *rbuf, int count
704707
if (NULL != free_buffer) {
705708
free(free_buffer);
706709
}
710+
if (NULL != inplace_temp_free) {
711+
free(inplace_temp_free);
712+
}
707713
return err;
708714
}
709715

ompi/mca/common/ompio/common_ompio_aggregators.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1303,12 +1303,14 @@ int mca_common_ompio_prepare_to_group(ompio_file_t *fh,
13031303
fh->f_comm);
13041304
if ( OMPI_SUCCESS != ret ) {
13051305
opal_output (1, "mca_common_ompio_prepare_to_group: error in ompi_fcoll_base_coll_allgather_array\n");
1306+
free(start_offsets_lens_tmp);
13061307
goto exit;
13071308
}
13081309
end_offsets_tmp = (OMPI_MPI_OFFSET_TYPE* )malloc (fh->f_init_procs_per_group * sizeof(OMPI_MPI_OFFSET_TYPE));
13091310
if (NULL == end_offsets_tmp) {
13101311
opal_output (1, "OUT OF MEMORY\n");
1311-
goto exit;
1312+
free(start_offsets_lens_tmp);
1313+
return OMPI_ERR_OUT_OF_RESOURCE;
13121314
}
13131315
for( k = 0 ; k < fh->f_init_procs_per_group; k++){
13141316
end_offsets_tmp[k] = start_offsets_lens_tmp[3*k] + start_offsets_lens_tmp[3*k+1];
@@ -1333,14 +1335,12 @@ int mca_common_ompio_prepare_to_group(ompio_file_t *fh,
13331335
if (NULL == aggr_bytes_per_group_tmp) {
13341336
opal_output (1, "OUT OF MEMORY\n");
13351337
ret = OMPI_ERR_OUT_OF_RESOURCE;
1336-
free(end_offsets_tmp);
13371338
goto exit;
13381339
}
13391340
decision_list_tmp = (int* )malloc (fh->f_init_num_aggrs * sizeof(int));
13401341
if (NULL == decision_list_tmp) {
13411342
opal_output (1, "OUT OF MEMORY\n");
13421343
ret = OMPI_ERR_OUT_OF_RESOURCE;
1343-
free(end_offsets_tmp);
13441344
if (NULL != aggr_bytes_per_group_tmp) {
13451345
free(aggr_bytes_per_group_tmp);
13461346
}

ompi/mca/osc/sm/osc_sm_component.c

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -278,8 +278,8 @@ component_select(struct ompi_win_t *win, void **base, size_t size, int disp_unit
278278
total += rbuf[i];
279279
}
280280

281-
/* user opal/shmem directly to create a shared memory segment */
282-
state_size = sizeof(ompi_osc_sm_global_state_t) + sizeof(ompi_osc_sm_node_state_t) * comm_size;
281+
/* user opal/shmem directly to create a shared memory segment */
282+
state_size = sizeof(ompi_osc_sm_global_state_t) + sizeof(ompi_osc_sm_node_state_t) * comm_size;
283283
state_size += OPAL_ALIGN_PAD_AMOUNT(state_size, 64);
284284
posts_size = comm_size * post_size * sizeof (module->posts[0][0]);
285285
posts_size += OPAL_ALIGN_PAD_AMOUNT(posts_size, 64);
@@ -289,34 +289,39 @@ component_select(struct ompi_win_t *win, void **base, size_t size, int disp_unit
289289
mca_osc_sm_component.backing_directory, ompi_process_info.nodename,
290290
OMPI_PROC_MY_NAME->jobid, (int) OMPI_PROC_MY_NAME->vpid, ompi_comm_get_cid(module->comm));
291291
if (ret < 0) {
292+
free(rbuf);
292293
return OMPI_ERR_OUT_OF_RESOURCE;
293294
}
294295

295296
ret = opal_shmem_segment_create (&module->seg_ds, data_file, total + pagesize + state_size + posts_size);
296297
free(data_file);
297298
if (OPAL_SUCCESS != ret) {
299+
free(rbuf);
298300
goto error;
299301
}
300302

301303
unlink_needed = true;
302304
}
303305

304-
ret = module->comm->c_coll->coll_bcast (&module->seg_ds, sizeof (module->seg_ds), MPI_BYTE, 0,
305-
module->comm, module->comm->c_coll->coll_bcast_module);
306-
if (OMPI_SUCCESS != ret) {
307-
goto error;
308-
}
306+
ret = module->comm->c_coll->coll_bcast (&module->seg_ds, sizeof (module->seg_ds), MPI_BYTE, 0,
307+
module->comm, module->comm->c_coll->coll_bcast_module);
308+
if (OMPI_SUCCESS != ret) {
309+
free(rbuf);
310+
goto error;
311+
}
309312

310-
module->segment_base = opal_shmem_segment_attach (&module->seg_ds);
311-
if (NULL == module->segment_base) {
312-
goto error;
313-
}
313+
module->segment_base = opal_shmem_segment_attach (&module->seg_ds);
314+
if (NULL == module->segment_base) {
315+
free(rbuf);
316+
goto error;
317+
}
314318

315319
/* wait for all processes to attach */
316-
ret = module->comm->c_coll->coll_barrier (module->comm, module->comm->c_coll->coll_barrier_module);
317-
if (OMPI_SUCCESS != ret) {
318-
goto error;
319-
}
320+
ret = module->comm->c_coll->coll_barrier (module->comm, module->comm->c_coll->coll_barrier_module);
321+
if (OMPI_SUCCESS != ret) {
322+
free(rbuf);
323+
goto error;
324+
}
320325

321326
if (0 == ompi_comm_rank (module->comm)) {
322327
opal_shmem_unlink (&module->seg_ds);

ompi/mca/osc/ucx/osc_ucx_active_target.c

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -110,12 +110,16 @@ int ompi_osc_ucx_start(struct ompi_group_t *group, int assert, struct ompi_win_t
110110

111111
ret = ompi_comm_group(module->comm, &win_group);
112112
if (ret != OMPI_SUCCESS) {
113+
free(ranks_in_grp);
114+
free(ranks_in_win_grp);
113115
return OMPI_ERROR;
114116
}
115117

116118
ret = ompi_group_translate_ranks(module->start_group, size, ranks_in_grp,
117119
win_group, ranks_in_win_grp);
118120
if (ret != OMPI_SUCCESS) {
121+
free(ranks_in_grp);
122+
free(ranks_in_win_grp);
119123
return OMPI_ERROR;
120124
}
121125

@@ -215,6 +219,11 @@ int ompi_osc_ucx_post(struct ompi_group_t *group, int assert, struct ompi_win_t
215219
int *ranks_in_grp = NULL, *ranks_in_win_grp = NULL;
216220
int myrank = ompi_comm_rank(module->comm);
217221

222+
ret = ompi_comm_group(module->comm, &win_group);
223+
if (ret != OMPI_SUCCESS) {
224+
return OMPI_ERROR;
225+
}
226+
218227
size = ompi_group_size(module->post_group);
219228
ranks_in_grp = malloc(sizeof(int) * size);
220229
ranks_in_win_grp = malloc(sizeof(int) * ompi_comm_size(module->comm));
@@ -223,15 +232,11 @@ int ompi_osc_ucx_post(struct ompi_group_t *group, int assert, struct ompi_win_t
223232
ranks_in_grp[i] = i;
224233
}
225234

226-
ret = ompi_comm_group(module->comm, &win_group);
227-
if (ret != OMPI_SUCCESS) {
228-
return OMPI_ERROR;
229-
}
230-
231235
ret = ompi_group_translate_ranks(module->post_group, size, ranks_in_grp,
232236
win_group, ranks_in_win_grp);
233237
if (ret != OMPI_SUCCESS) {
234-
return OMPI_ERROR;
238+
ret = OMPI_ERROR;
239+
goto cleanup;
235240
}
236241

237242
for (i = 0; i < size; i++) {
@@ -243,7 +248,8 @@ int ompi_osc_ucx_post(struct ompi_group_t *group, int assert, struct ompi_win_t
243248
1, ranks_in_win_grp[i], &result,
244249
sizeof(result), remote_addr);
245250
if (ret != OMPI_SUCCESS) {
246-
return OMPI_ERROR;
251+
ret = OMPI_ERROR;
252+
goto cleanup;
247253
}
248254

249255
curr_idx = result & (OMPI_OSC_UCX_POST_PEER_MAX - 1);
@@ -256,7 +262,8 @@ int ompi_osc_ucx_post(struct ompi_group_t *group, int assert, struct ompi_win_t
256262
myrank + 1, &result, sizeof(result),
257263
remote_addr);
258264
if (ret != OMPI_SUCCESS) {
259-
return OMPI_ERROR;
265+
ret = OMPI_ERROR;
266+
goto cleanup;
260267
}
261268

262269
if (result == 0)
@@ -277,9 +284,11 @@ int ompi_osc_ucx_post(struct ompi_group_t *group, int assert, struct ompi_win_t
277284
} while (1);
278285
}
279286

287+
cleanup:
280288
free(ranks_in_grp);
281289
free(ranks_in_win_grp);
282290
ompi_group_free(&win_group);
291+
if (OMPI_SUCCESS != ret) return ret;
283292
}
284293

285294
module->epoch_type.exposure = POST_WAIT_EPOCH;

ompi/mca/osc/ucx/osc_ucx_comm.c

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -140,15 +140,15 @@ static inline int ddt_put_get(ompi_osc_ucx_module_t *module,
140140
ret = create_iov_list(origin_addr, origin_count, origin_dt,
141141
&origin_ucx_iov, &origin_ucx_iov_count);
142142
if (ret != OMPI_SUCCESS) {
143-
return ret;
143+
goto cleanup;
144144
}
145145
}
146146

147147
if (!is_target_contig) {
148148
ret = create_iov_list(NULL, target_count, target_dt,
149149
&target_ucx_iov, &target_ucx_iov_count);
150150
if (ret != OMPI_SUCCESS) {
151-
return ret;
151+
goto cleanup;
152152
}
153153
}
154154

@@ -168,7 +168,8 @@ static inline int ddt_put_get(ompi_osc_ucx_module_t *module,
168168
remote_addr + (uint64_t)(target_ucx_iov[target_ucx_iov_idx].addr));
169169
if (OPAL_SUCCESS != status) {
170170
OSC_UCX_VERBOSE(1, "opal_common_ucx_mem_putget failed: %d", status);
171-
return OMPI_ERROR;
171+
ret = OMPI_ERROR;
172+
goto cleanup;
172173
}
173174

174175
origin_ucx_iov[origin_ucx_iov_idx].addr = (void *)((intptr_t)origin_ucx_iov[origin_ucx_iov_idx].addr + curr_len);
@@ -202,7 +203,8 @@ static inline int ddt_put_get(ompi_osc_ucx_module_t *module,
202203
remote_addr + target_lb + prev_len);
203204
if (OPAL_SUCCESS != status) {
204205
OSC_UCX_VERBOSE(1, "opal_common_ucx_mem_putget failed: %d", status);
205-
return OMPI_ERROR;
206+
ret = OMPI_ERROR;
207+
goto cleanup;
206208
}
207209

208210
prev_len += origin_ucx_iov[origin_ucx_iov_idx].len;
@@ -224,14 +226,17 @@ static inline int ddt_put_get(ompi_osc_ucx_module_t *module,
224226
remote_addr + (uint64_t)(target_ucx_iov[target_ucx_iov_idx].addr));
225227
if (OPAL_SUCCESS != status) {
226228
OSC_UCX_VERBOSE(1, "opal_common_ucx_mem_putget failed: %d", status);
227-
return OMPI_ERROR;
229+
ret = OMPI_ERROR;
230+
goto cleanup;
228231
}
229232

230233
prev_len += target_ucx_iov[target_ucx_iov_idx].len;
231234
target_ucx_iov_idx++;
232235
}
233236
}
234237

238+
cleanup:
239+
235240
if (origin_ucx_iov != NULL) {
236241
free(origin_ucx_iov);
237242
}
@@ -338,12 +343,14 @@ static inline int get_dynamic_win_info(uint64_t remote_addr, ompi_osc_ucx_module
338343
len, remote_state_addr);
339344
if (OPAL_SUCCESS != ret) {
340345
OSC_UCX_VERBOSE(1, "opal_common_ucx_mem_putget failed: %d", ret);
341-
return OMPI_ERROR;
346+
ret = OMPI_ERROR;
347+
goto cleanup;
342348
}
343349

344350
ret = opal_common_ucx_wpmem_flush(module->state_mem, OPAL_COMMON_UCX_SCOPE_EP, target);
345-
if (ret != OMPI_SUCCESS) {
346-
return ret;
351+
if (ret != OPAL_SUCCESS) {
352+
ret = OMPI_ERROR;
353+
goto cleanup;
347354
}
348355

349356
memcpy(&win_count, temp_buf, sizeof(uint64_t));
@@ -365,6 +372,7 @@ static inline int get_dynamic_win_info(uint64_t remote_addr, ompi_osc_ucx_module
365372
temp_dynamic_wins[contain].mem_addr, OMPI_OSC_UCX_MEM_ADDR_MAX_LEN);
366373
module->local_dynamic_win_info[contain].mem->mem_displs[target] = target * OMPI_OSC_UCX_MEM_ADDR_MAX_LEN;
367374

375+
cleanup:
368376
free(temp_buf);
369377

370378
return ret;
@@ -652,11 +660,13 @@ int accumulate_req(const void *origin_addr, int origin_count,
652660
ret = ompi_osc_ucx_get(temp_addr, (int)temp_count, temp_dt,
653661
target, target_disp, target_count, target_dt, win);
654662
if (ret != OMPI_SUCCESS) {
663+
free(temp_addr);
655664
return ret;
656665
}
657666

658667
ret = opal_common_ucx_wpmem_flush(module->mem, OPAL_COMMON_UCX_SCOPE_EP, target);
659668
if (ret != OMPI_SUCCESS) {
669+
free(temp_addr);
660670
return ret;
661671
}
662672

@@ -670,6 +680,7 @@ int accumulate_req(const void *origin_addr, int origin_count,
670680
ret = create_iov_list(origin_addr, origin_count, origin_dt,
671681
&origin_ucx_iov, &origin_ucx_iov_count);
672682
if (ret != OMPI_SUCCESS) {
683+
free(temp_addr);
673684
return ret;
674685
}
675686

@@ -707,6 +718,7 @@ int accumulate_req(const void *origin_addr, int origin_count,
707718
ret = ompi_osc_ucx_put(temp_addr, (int)temp_count, temp_dt, target, target_disp,
708719
target_count, target_dt, win);
709720
if (ret != OMPI_SUCCESS) {
721+
free(temp_addr);
710722
return ret;
711723
}
712724

@@ -741,6 +753,7 @@ do_atomic_compare_and_swap(const void *origin_addr, const void *compare_addr,
741753
if (!module->acc_single_intrinsic) {
742754
ret = start_atomicity(module, target, &lock_acquired);
743755
if (ret != OMPI_SUCCESS) {
756+
free(temp_addr);
744757
return ret;
745758
}
746759
}

ompi/mca/topo/treematch/topo_treematch_dist_graph_create.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,7 @@ int mca_topo_treematch_dist_graph_create(mca_topo_base_module_t* topo_module,
204204
* and create a duplicate of the original communicator */
205205
free(vpids);
206206
free(colors);
207+
free(lindex_to_grank);
207208
goto fallback; /* return with success */
208209
}
209210
/* compute local roots ranks in comm_old */
@@ -250,6 +251,7 @@ int mca_topo_treematch_dist_graph_create(mca_topo_base_module_t* topo_module,
250251
}
251252
if( (0 == num_objs_in_node) || (0 == num_pus_in_node) ) { /* deal with bozo cases: COVERITY 1418505 */
252253
free(colors);
254+
free(lindex_to_grank);
253255
goto fallback; /* return with success */
254256
}
255257
/* Check for oversubscribing */
@@ -288,6 +290,7 @@ int mca_topo_treematch_dist_graph_create(mca_topo_base_module_t* topo_module,
288290
object = hwloc_get_obj_by_depth(opal_hwloc_topology, effective_depth, obj_rank);
289291
if( NULL == object) {
290292
free(colors);
293+
free(lindex_to_grank);
291294
hwloc_bitmap_free(set);
292295
goto fallback; /* return with success */
293296
}
@@ -315,6 +318,7 @@ int mca_topo_treematch_dist_graph_create(mca_topo_base_module_t* topo_module,
315318
OPAL_OUTPUT_VERBOSE((10, ompi_topo_base_framework.framework_output,
316319
"Oversubscribing PUs resources => Rank Reordering Impossible \n"));
317320
free(colors);
321+
free(lindex_to_grank);
318322
hwloc_bitmap_free(set);
319323
goto fallback; /* return with success */
320324
}

opal/mca/base/mca_base_alias.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,10 +143,12 @@ int mca_base_alias_register (const char *project, const char *framework, const c
143143

144144
opal_hash_table_set_value_ptr (alias_hash_table, name, strlen(name), alias);
145145
free (name);
146+
name = NULL;
146147
}
147148

148149
mca_base_alias_item_t *alias_item = OBJ_NEW(mca_base_alias_item_t);
149150
if (NULL == alias_item) {
151+
if (NULL != name) free(name);
150152
return OPAL_ERR_OUT_OF_RESOURCE;
151153
}
152154

opal/mca/btl/tcp/btl_tcp_component.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1234,6 +1234,7 @@ static int mca_btl_tcp_component_exchange(void)
12341234
opal_net_get_hostname(addr));
12351235
} else {
12361236
BTL_ERROR(("Unexpected address family: %d", addr->sa_family));
1237+
free(addrs);
12371238
return OPAL_ERR_BAD_PARAM;
12381239
}
12391240

0 commit comments

Comments
 (0)