From 9f13425980cf017248dde66b8533ae69e24d798a Mon Sep 17 00:00:00 2001 From: Gilles Gouaillardet Date: Tue, 3 Mar 2015 14:38:34 +0900 Subject: [PATCH] fbtl/posix: fix misc memory leaks as reported by Coverity with CIDs 72125, 72126, 1269899 and 1269900 --- ompi/mca/fbtl/posix/fbtl_posix_ipreadv.c | 10 +++++++++- ompi/mca/fbtl/posix/fbtl_posix_ipwritev.c | 10 +++++++++- ompi/mca/fbtl/posix/fbtl_posix_preadv.c | 14 +++++++------- ompi/mca/fbtl/posix/fbtl_posix_pwritev.c | 16 ++++++++-------- 4 files changed, 33 insertions(+), 17 deletions(-) diff --git a/ompi/mca/fbtl/posix/fbtl_posix_ipreadv.c b/ompi/mca/fbtl/posix/fbtl_posix_ipreadv.c index 41cc861766..ee4ac2b034 100644 --- a/ompi/mca/fbtl/posix/fbtl_posix_ipreadv.c +++ b/ompi/mca/fbtl/posix/fbtl_posix_ipreadv.c @@ -10,6 +10,8 @@ * Copyright (c) 2004-2005 The Regents of the University of California. * All rights reserved. * Copyright (c) 2008-2015 University of Houston. All rights reserved. + * Copyright (c) 2015 Research Organization for Information Science + * and Technology (RIST). All rights reserved. * $COPYRIGHT$ * * Additional copyrights may follow @@ -54,12 +56,15 @@ ssize_t mca_fbtl_posix_ipreadv (mca_io_ompio_file_t *fh, fh->f_num_of_io_entries); if (NULL == data->aio_reqs) { opal_output(1, "OUT OF MEMORY\n"); + free(data); return 0; } data->aio_req_status = (int *) malloc (sizeof(int) * fh->f_num_of_io_entries); if (NULL == data->aio_req_status) { opal_output(1, "OUT OF MEMORY\n"); + free(data->aio_reqs); + free(data); return 0; } @@ -83,7 +88,10 @@ ssize_t mca_fbtl_posix_ipreadv (mca_io_ompio_file_t *fh, } for (i=0; i < data->aio_last_active_req; i++) { if (-1 == aio_read(&data->aio_reqs[i])) { - perror("aio_read() error"); + opal_output(1, "aio_read() error: %s", strerror(errno)); + free(data->aio_reqs); + free(data->aio_req_status); + free(data); return OMPI_ERROR; } } diff --git a/ompi/mca/fbtl/posix/fbtl_posix_ipwritev.c b/ompi/mca/fbtl/posix/fbtl_posix_ipwritev.c index acc1ffd789..058b5eb723 100644 --- a/ompi/mca/fbtl/posix/fbtl_posix_ipwritev.c +++ b/ompi/mca/fbtl/posix/fbtl_posix_ipwritev.c @@ -10,6 +10,8 @@ * Copyright (c) 2004-2005 The Regents of the University of California. * All rights reserved. * Copyright (c) 2008-2015 University of Houston. All rights reserved. + * Copyright (c) 2015 Research Organization for Information Science + * and Technology (RIST). All rights reserved. * $COPYRIGHT$ * * Additional copyrights may follow @@ -53,12 +55,15 @@ ssize_t mca_fbtl_posix_ipwritev (mca_io_ompio_file_t *fh, fh->f_num_of_io_entries); if (NULL == data->aio_reqs) { opal_output(1, "OUT OF MEMORY\n"); + free(data); return 0; } data->aio_req_status = (int *) malloc (sizeof(int) * fh->f_num_of_io_entries); if (NULL == data->aio_req_status) { opal_output(1, "OUT OF MEMORY\n"); + free(data->aio_reqs); + free(data); return 0; } @@ -83,7 +88,10 @@ ssize_t mca_fbtl_posix_ipwritev (mca_io_ompio_file_t *fh, for (i=0; i < data->aio_last_active_req; i++) { if (-1 == aio_write(&data->aio_reqs[i])) { - perror("aio_write() error"); + opal_output(1, "aio_write() error: %s", strerror(errno)); + free(data->aio_req_status); + free(data->aio_reqs); + free(data); return OMPI_ERROR; } } diff --git a/ompi/mca/fbtl/posix/fbtl_posix_preadv.c b/ompi/mca/fbtl/posix/fbtl_posix_preadv.c index 76b9ed1dfc..7fd8b0ab9d 100644 --- a/ompi/mca/fbtl/posix/fbtl_posix_preadv.c +++ b/ompi/mca/fbtl/posix/fbtl_posix_preadv.c @@ -10,6 +10,8 @@ * Copyright (c) 2004-2005 The Regents of the University of California. * All rights reserved. * Copyright (c) 2008-2014 University of Houston. All rights reserved. + * Copyright (c) 2015 Research Organization for Information Science + * and Technology (RIST). All rights reserved. * $COPYRIGHT$ * * Additional copyrights may follow @@ -79,7 +81,8 @@ ssize_t mca_fbtl_posix_preadv (mca_io_ompio_file_t *fh ) } if (-1 == lseek (fh->fd, iov_offset, SEEK_SET)) { - perror ("fseek"); + opal_output(1, "lseek:%s", strerror(errno)); + free(iov); return OMPI_ERROR; } ret_code = readv (fh->fd, iov, iov_count); @@ -87,7 +90,8 @@ ssize_t mca_fbtl_posix_preadv (mca_io_ompio_file_t *fh ) bytes_read+=ret_code; } else if ( ret_code == -1 ) { - perror ("readv"); + opal_output(1, "readv:%s", strerror(errno)); + free(iov); return OMPI_ERROR; } else if ( 0 == ret_code ){ @@ -97,11 +101,7 @@ ssize_t mca_fbtl_posix_preadv (mca_io_ompio_file_t *fh ) iov_count = 0; } - if (NULL != iov) { - free (iov); - iov = NULL; - } - + free (iov); return bytes_read; } diff --git a/ompi/mca/fbtl/posix/fbtl_posix_pwritev.c b/ompi/mca/fbtl/posix/fbtl_posix_pwritev.c index e14410df30..bcf616693b 100644 --- a/ompi/mca/fbtl/posix/fbtl_posix_pwritev.c +++ b/ompi/mca/fbtl/posix/fbtl_posix_pwritev.c @@ -10,6 +10,8 @@ * Copyright (c) 2004-2005 The Regents of the University of California. * All rights reserved. * Copyright (c) 2008-2014 University of Houston. All rights reserved. + * Copyright (c) 2015 Research Organization for Information Science + * and Technology (RIST). All rights reserved. * $COPYRIGHT$ * * Additional copyrights may follow @@ -92,7 +94,8 @@ ssize_t mca_fbtl_posix_pwritev(mca_io_ompio_file_t *fh ) */ if (-1 == lseek (fh->fd, iov_offset, SEEK_SET)) { - perror ("lseek"); + opal_output(1, "lseek:%s", strerror(errno)); + free(iov); return OMPI_ERROR; } ret_code = writev (fh->fd, iov, iov_count); @@ -100,17 +103,14 @@ ssize_t mca_fbtl_posix_pwritev(mca_io_ompio_file_t *fh ) bytes_written += ret_code; } else if (-1 == ret_code ) { - perror ("writev"); - goto exit; + opal_output(1, "writev:%s", strerror(errno)); + free (iov); + return OMPI_ERROR; } iov_count = 0; } -exit: - if (NULL != iov) { - free (iov); - iov = NULL; - } + free (iov); return bytes_written; }