From 971711474f9fb9fe2894a6f748aa13d9f8146942 Mon Sep 17 00:00:00 2001 From: George Bosilca Date: Thu, 14 Apr 2011 21:50:06 +0000 Subject: [PATCH] Based on the patch submitted by Pascal Deveze, here is the memory leak fix for the type indexed creation. CMR v1.4 and v1.5. This commit was SVN r24617. --- ompi/datatype/ompi_datatype_create_indexed.c | 62 ++++++++------------ 1 file changed, 26 insertions(+), 36 deletions(-) diff --git a/ompi/datatype/ompi_datatype_create_indexed.c b/ompi/datatype/ompi_datatype_create_indexed.c index 1d8eb6c9c9..0ecfd72258 100644 --- a/ompi/datatype/ompi_datatype_create_indexed.c +++ b/ompi/datatype/ompi_datatype_create_indexed.c @@ -3,7 +3,7 @@ * Copyright (c) 2004-2006 The Trustees of Indiana University and Indiana * University Research and Technology * Corporation. All rights reserved. - * Copyright (c) 2004-2009 The University of Tennessee and The University + * Copyright (c) 2004-2010 The University of Tennessee and The University * of Tennessee Research Foundation. All rights * reserved. * Copyright (c) 2004-2006 High Performance Computing Center Stuttgart, @@ -46,26 +46,21 @@ int32_t ompi_datatype_create_indexed( int count, const int* pBlockLength, const dLength = pBlockLength[0]; endat = disp + dLength; ompi_datatype_type_extent( oldType, &extent ); - if( 1 >= count ) { - pdt = ompi_datatype_create( oldType->super.desc.used + 2 ); - /* multiply by count to make it zero if count is zero */ - ompi_datatype_add( pdt, oldType, count * dLength, disp * extent, extent ); - } else { - pdt = ompi_datatype_create( count * (2 + oldType->super.desc.used) ); - for( i = 1; i < count; i++ ) { - if( endat == pDisp[i] ) { - /* contiguous with the previsious */ - dLength += pBlockLength[i]; - endat += pBlockLength[i]; - } else { - ompi_datatype_add( pdt, oldType, dLength, disp * extent, extent ); - disp = pDisp[i]; - dLength = pBlockLength[i]; - endat = disp + pBlockLength[i]; - } + + pdt = ompi_datatype_create( count * (2 + oldType->super.desc.used) ); + for( i = 1; i < count; i++ ) { + if( endat == pDisp[i] ) { + /* contiguous with the previsious */ + dLength += pBlockLength[i]; + endat += pBlockLength[i]; + } else { + ompi_datatype_add( pdt, oldType, dLength, disp * extent, extent ); + disp = pDisp[i]; + dLength = pBlockLength[i]; + endat = disp + pBlockLength[i]; } - ompi_datatype_add( pdt, oldType, dLength, disp * extent, extent ); } + ompi_datatype_add( pdt, oldType, dLength, disp * extent, extent ); *newType = pdt; return OMPI_SUCCESS; @@ -91,25 +86,20 @@ int32_t ompi_datatype_create_hindexed( int count, const int* pBlockLength, const dLength = pBlockLength[0]; endat = disp + dLength * extent; - if( 1 >= count ) { - pdt = ompi_datatype_create( oldType->super.desc.used + 2 ); - /* multiply by count to make it zero if count is zero */ - ompi_datatype_add( pdt, oldType, count * dLength, disp, extent ); - } else { - for( i = 1; i < count; i++ ) { - if( endat == pDisp[i] ) { - /* contiguous with the previsious */ - dLength += pBlockLength[i]; - endat += pBlockLength[i] * extent; - } else { - ompi_datatype_add( pdt, oldType, dLength, disp, extent ); - disp = pDisp[i]; - dLength = pBlockLength[i]; - endat = disp + pBlockLength[i] * extent; - } + for( i = 1; i < count; i++ ) { + if( endat == pDisp[i] ) { + /* contiguous with the previsious */ + dLength += pBlockLength[i]; + endat += pBlockLength[i] * extent; + } else { + ompi_datatype_add( pdt, oldType, dLength, disp, extent ); + disp = pDisp[i]; + dLength = pBlockLength[i]; + endat = disp + pBlockLength[i] * extent; } - ompi_datatype_add( pdt, oldType, dLength, disp, extent ); } + ompi_datatype_add( pdt, oldType, dLength, disp, extent ); + *newType = pdt; return OMPI_SUCCESS; }