From e80b7e9ddefd6ec66ba736ef8ae2be312b0e16d3 Mon Sep 17 00:00:00 2001 From: Jeff Squyres Date: Wed, 25 Jul 2007 01:00:30 +0000 Subject: [PATCH] If MPI_ALLOC_MEM is invoked with a 0 sized request, return NULL. If MPI_FREE_MEM is invoked with NULL, return success. Fixes trac:1101. This commit was SVN r15593. The following Trac tickets were found above: Ticket 1101 --> https://svn.open-mpi.org/trac/ompi/ticket/1101 --- ompi/mpi/c/alloc_mem.c | 14 ++++++++++++++ ompi/mpi/c/free_mem.c | 16 ++++++++-------- 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/ompi/mpi/c/alloc_mem.c b/ompi/mpi/c/alloc_mem.c index 4bb07ae852..8980b417cf 100644 --- a/ompi/mpi/c/alloc_mem.c +++ b/ompi/mpi/c/alloc_mem.c @@ -9,6 +9,7 @@ * University of Stuttgart. All rights reserved. * Copyright (c) 2004-2005 The Regents of the University of California. * All rights reserved. + * Copyright (c) 2007 Cisco, Inc. All rights reserved. * $COPYRIGHT$ * * Additional copyrights may follow @@ -52,6 +53,19 @@ int MPI_Alloc_mem(MPI_Aint size, MPI_Info info, void *baseptr) } } + /* Per these threads: + + http://www.open-mpi.org/community/lists/devel/2007/07/1977.php + http://www.open-mpi.org/community/lists/devel/2007/07/1979.php + + If you call MPI_ALLOC_MEM with a size of 0, you get NULL + back .*/ + if (0 == size) { + *((void **) baseptr) = NULL; + printf("0 size mem_alloc\n"); + return MPI_SUCCESS; + } + *((void **) baseptr) = mca_mpool_base_alloc((size_t) size, info); if (NULL == *((void **) baseptr)) { return OMPI_ERRHANDLER_INVOKE(MPI_COMM_WORLD, MPI_ERR_NO_MEM, diff --git a/ompi/mpi/c/free_mem.c b/ompi/mpi/c/free_mem.c index 44b01f9d10..abb569bf46 100644 --- a/ompi/mpi/c/free_mem.c +++ b/ompi/mpi/c/free_mem.c @@ -9,6 +9,7 @@ * University of Stuttgart. All rights reserved. * Copyright (c) 2004-2005 The Regents of the University of California. * All rights reserved. + * Copyright (c) 2007 Cisco, Inc. All rights reserved. * $COPYRIGHT$ * * Additional copyrights may follow @@ -39,15 +40,14 @@ int MPI_Free_mem(void *baseptr) { OPAL_CR_TEST_CHECKPOINT_READY(); - if (MPI_PARAM_CHECK) { - if (NULL == baseptr) { - return OMPI_ERRHANDLER_INVOKE(MPI_COMM_WORLD, MPI_ERR_ARG, - FUNC_NAME); - } - } + /* Per these threads: - if(OMPI_SUCCESS != mca_mpool_base_free(baseptr)) - { + http://www.open-mpi.org/community/lists/devel/2007/07/1977.php + http://www.open-mpi.org/community/lists/devel/2007/07/1979.php + + If you call MPI_ALLOC_MEM with a size of 0, you get NULL + back. So don't consider a NULL==baseptr an error. */ + if (NULL != baseptr && OMPI_SUCCESS != mca_mpool_base_free(baseptr)) { return OMPI_ERRHANDLER_INVOKE(MPI_COMM_WORLD, MPI_ERR_NO_MEM, FUNC_NAME); }