Skip to content

Commit 8f19c79

Browse files
committed
osc/sm: fix remaining coverity issues
Fixes CID 1324870: Memory - illegal accesses (USE_AFTER_FREE) Free osc module after calling destruct on the lock. Fixes CID 1324868: Integer handling issues (OVERFLOW_BEFORE_WIDEN) Fixes CID 1324867: Integer handling issues (OVERFLOW_BEFORE_WIDEN) Explicitly cast to uint64_t to ensure the widen happens before an overflow can occur. (cherry picked from commit open-mpi/ompi@2482122) Signed-off-by: Nathan Hjelm <[email protected]>
1 parent 5356d64 commit 8f19c79

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

ompi/mca/osc/sm/osc_sm_active_target.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ ompi_osc_sm_start(struct ompi_group_t *group,
147147

148148
for (int i = 0 ; i < size ; ++i) {
149149
int rank_byte = ranks[i] >> 6;
150-
uint64_t old, rank_bit = 1 << (ranks[i] & 0x3f);
150+
uint64_t old, rank_bit = ((uint64_t) 1) << (ranks[i] & 0x3f);
151151

152152
/* wait for rank to post */
153153
while (!(module->posts[my_rank][rank_byte] & rank_bit)) {
@@ -216,7 +216,7 @@ ompi_osc_sm_post(struct ompi_group_t *group,
216216
(ompi_osc_sm_module_t*) win->w_osc_module;
217217
int my_rank = ompi_comm_rank (module->comm);
218218
int my_byte = my_rank >> 6;
219-
uint64_t my_bit = 1 << (my_rank & 0x3f);
219+
uint64_t my_bit = ((uint64_t) 1) << (my_rank & 0x3f);
220220
int gsize;
221221

222222
OPAL_THREAD_LOCK(&module->lock);

ompi/mca/osc/sm/osc_sm_component.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -483,10 +483,11 @@ ompi_osc_sm_free(struct ompi_win_t *win)
483483

484484
/* cleanup */
485485
ompi_comm_free(&module->comm);
486-
free(module);
487486

488487
OBJ_DESTRUCT(&module->lock);
489488

489+
free(module);
490+
490491
return OMPI_SUCCESS;
491492
}
492493

0 commit comments

Comments
 (0)