Skip to content

Commit 6836f50

Browse files
David Woottonjjhursey
authored andcommitted
Fix memory leak in ompi_coll_base_reduce_intra_in_order_binary: Coverity CID 1397316
Coverity static analysis reports a memory leak in ompi_coll_base_reduce_intra_in_order_binary The memory leak occurs if the call to ompi_coll_base_reduce_intra_in_order_binary fails, since tmpbuf_free is not freed until after the error status check. This is fixed by moving the free(tmpbif_free) statement to just before the status check. Signed-off-by: David Wootton <dwootton@us.ibm.com> Signed-off-by: Joshua Hursey <jhursey@us.ibm.com>
1 parent fefae1a commit 6836f50

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

ompi/mca/coll/base/coll_base_reduce.c

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -583,7 +583,10 @@ int ompi_coll_base_reduce_intra_in_order_binary( const void *sendbuf, void *recv
583583
op, io_root, comm, module,
584584
data->cached_in_order_bintree,
585585
segcount, max_outstanding_reqs );
586-
if (MPI_SUCCESS != ret) { return ret; }
586+
if (MPI_SUCCESS != ret) {
587+
free(tmpbuf_free);
588+
return ret;
589+
}
587590

588591
/* Clean up */
589592
if (io_root != root) {
@@ -592,14 +595,20 @@ int ompi_coll_base_reduce_intra_in_order_binary( const void *sendbuf, void *recv
592595
ret = MCA_PML_CALL(recv(recvbuf, count, datatype, io_root,
593596
MCA_COLL_BASE_TAG_REDUCE, comm,
594597
MPI_STATUS_IGNORE));
595-
if (MPI_SUCCESS != ret) { return ret; }
598+
if (MPI_SUCCESS != ret) {
599+
free(tmpbuf_free);
600+
return ret;
601+
}
596602

597603
} else if (io_root == rank) {
598604
/* Send result from use_this_recvbuf to root */
599605
ret = MCA_PML_CALL(send(use_this_recvbuf, count, datatype, root,
600606
MCA_COLL_BASE_TAG_REDUCE,
601607
MCA_PML_BASE_SEND_STANDARD, comm));
602-
if (MPI_SUCCESS != ret) { return ret; }
608+
if (MPI_SUCCESS != ret) {
609+
free(tmpbuf_free);
610+
return ret;
611+
}
603612
}
604613
}
605614
if (NULL != tmpbuf_free) {

0 commit comments

Comments
 (0)