From 90a9c12fdbff270c9d1f375da2075d5fd9ba6ab1 Mon Sep 17 00:00:00 2001 From: Gilles Gouaillardet Date: Tue, 22 Jan 2019 10:57:57 +0900 Subject: [PATCH 1/2] opal/datatype: plug a memory leak in opal_datatype_t destructor correctly free ptypes if the datatype is not pre-defined. Thanks Axel Huebl for reporting this. Refs. open-mpi/ompi#6291 Signed-off-by: Gilles Gouaillardet (cherry picked from commit 7c938f070fa8c906918507dbc78fdadcde324610) --- opal/datatype/opal_datatype_create.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/opal/datatype/opal_datatype_create.c b/opal/datatype/opal_datatype_create.c index 0e6d49b9bd..122521989b 100644 --- a/opal/datatype/opal_datatype_create.c +++ b/opal/datatype/opal_datatype_create.c @@ -11,6 +11,8 @@ * Copyright (c) 2004-2006 The Regents of the University of California. * All rights reserved. * Copyright (c) 2009 Oak Ridge National Labs. All rights reserved. + * Copyright (c) 2019 Research Organization for Information Science + * and Technology (RIST). All rights reserved. * $COPYRIGHT$ * * Additional copyrights may follow @@ -77,7 +79,7 @@ static void opal_datatype_destruct( opal_datatype_t* datatype ) } } /* dont free the ptypes of predefined types (it was not dynamically allocated) */ - if( (NULL != datatype->ptypes) && (datatype->id >= OPAL_DATATYPE_MAX_PREDEFINED) ) { + if( (NULL != datatype->ptypes) && (!opal_datatype_is_predefined(datatype)) ) { free(datatype->ptypes); datatype->ptypes = NULL; } From 0ae48475a132c61e9129ec5f401b96169a71617d Mon Sep 17 00:00:00 2001 From: Gilles Gouaillardet Date: Fri, 1 Feb 2019 11:20:13 +0900 Subject: [PATCH 2/2] opal/datatype: reset ptypes in opal_datatype_clone() Reset ptypes when cloning a datatype in order to prevent a double free() in the opal_datatype_t destructor. This fixes a bug introduced in open-mpi/ompi@7c938f070fa8c906918507dbc78fdadcde324610 Fixes open-mpi/ompi#6346 Signed-off-by: Gilles Gouaillardet (cherry picked from commit open-mpi/ompi@b395342c9fbdc28f59e01d393d34a6b0c651180e) --- opal/datatype/opal_datatype_clone.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/opal/datatype/opal_datatype_clone.c b/opal/datatype/opal_datatype_clone.c index fa4479982d..59e82bb40c 100644 --- a/opal/datatype/opal_datatype_clone.c +++ b/opal/datatype/opal_datatype_clone.c @@ -12,6 +12,8 @@ * All rights reserved. * Copyright (c) 2009 Sun Microsystems, Inc. All rights reserved. * Copyright (c) 2009 Oak Ridge National Labs. All rights reserved. + * Copyright (c) 2019 Research Organization for Information Science + * and Technology (RIST). All rights reserved. * $COPYRIGHT$ * * Additional copyrights may follow @@ -41,6 +43,7 @@ int32_t opal_datatype_clone( const opal_datatype_t * src_type, opal_datatype_t * sizeof(opal_datatype_t)-sizeof(opal_object_t) ); dest_type->flags &= (~OPAL_DATATYPE_FLAG_PREDEFINED); + dest_type->ptypes = NULL; dest_type->desc.desc = temp; /**