Skip to content

Commit

Permalink
osc: fix coverity issues
Browse files Browse the repository at this point in the history
Fix CID 1324726 (#1 of 1): Free of address-of expression (BAD_FREE):

Indeed, if a lock conflicts with the lock_all we will end up trying to
free an invalid pointer.

Fix CID 1328826 (#1 of 1): Dereference after null check (FORWARD_NULL):

This was intentional but it would be a good idea to check for
module->comm being non_NULL to be safe. Also cleaned out some checks
for NULL before free().

Signed-off-by: Nathan Hjelm <hjelmn@lanl.gov>
  • Loading branch information
hjelmn committed Mar 18, 2016
1 parent 013aec8 commit 2ed4501
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 13 deletions.
4 changes: 3 additions & 1 deletion ompi/mca/osc/pt2pt/osc_pt2pt_passive_target.c
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,9 @@ static int ompi_osc_pt2pt_lock_internal (int lock_type, int target, int assert,

/* check for conflicting lock */
if (ompi_osc_pt2pt_module_lock_find (module, target, NULL)) {
ompi_osc_pt2pt_sync_return (lock);
if (&module->all_sync != lock) {
ompi_osc_pt2pt_sync_return (lock);
}
OPAL_THREAD_UNLOCK(&module->lock);
return OMPI_ERR_RMA_CONFLICT;
}
Expand Down
17 changes: 5 additions & 12 deletions ompi/mca/osc/rdma/osc_rdma_module.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* University of Stuttgart. All rights reserved.
* Copyright (c) 2004-2005 The Regents of the University of California.
* All rights reserved.
* Copyright (c) 2007-2015 Los Alamos National Security, LLC. All rights
* Copyright (c) 2007-2016 Los Alamos National Security, LLC. All rights
* reserved.
* Copyright (c) 2012-2013 Sandia National Laboratories. All rights reserved.
* $COPYRIGHT$
Expand Down Expand Up @@ -103,18 +103,12 @@ int ompi_osc_rdma_free(ompi_win_t *win)
}

OBJ_DESTRUCT(&module->peer_hash);
} else {
} else if (NULL != module->comm) {
for (int i = 0 ; i < ompi_comm_rank (module->comm) ; ++i) {
if (NULL != module->peer_array[i]) {
OBJ_RELEASE(module->peer_array[i]);
}
}

free (module->peer_array);
}

if (NULL != module->outstanding_lock_array) {
free (module->outstanding_lock_array);
}

if (module->local_leaders && MPI_COMM_NULL != module->local_leaders) {
Expand All @@ -129,15 +123,14 @@ int ompi_osc_rdma_free(ompi_win_t *win)
ompi_comm_free (&module->comm);
}

if (NULL != module->free_after) {
free(module->free_after);
}

if (module->segment_base) {
opal_shmem_segment_detach (&module->seg_ds);
module->segment_base = NULL;
}

free (module->peer_array);
free (module->outstanding_lock_array);
free (module->free_after);
free (module);

return OMPI_SUCCESS;
Expand Down

0 comments on commit 2ed4501

Please sign in to comment.