From 9f5d60af1a3f509d20446cc505ed1b147eb099ed Mon Sep 17 00:00:00 2001
From: Matthieu Schaller <matthieu.schaller@durhama.ac.uk>
Date: Mon, 4 May 2015 12:20:09 +0100
Subject: [PATCH] Corrected the hdf5-parallel reading rountines. Some opened
 HDF5 handlers were not closed.

Former-commit-id: fc37163f8d83698596618fc411e929b988aa335a
---
 src/parallel_io.c | 20 +++++++++++---------
 1 file changed, 11 insertions(+), 9 deletions(-)

diff --git a/src/parallel_io.c b/src/parallel_io.c
index bc8206e978..92e0b282fd 100644
--- a/src/parallel_io.c
+++ b/src/parallel_io.c
@@ -90,24 +90,19 @@ void readArrayBackEnd(hid_t grp, char* name, enum DATA_TYPE type, int N, int dim
 	  error( "Compulsory data set '%s' not present in the file." , name );
 	}
       else
-	{
-	  /* message("Optional data set '%s' not present. Zeroing this particle field...", name);	   */
-	  
+	{	  
 	  for(i=0; i<N; ++i)
 	    memset(part_c+i*partSize, 0, copySize);
-	  
 	  return;
 	}
-   }
+    }
 
   /* message( "Reading %s '%s' array...", importance == COMPULSORY ? "compulsory": "optional  ", name); */
 
   /* Open data space in file */
   h_data = H5Dopen2(grp, name, H5P_DEFAULT);
   if(h_data < 0)
-    {
-      error( "Error while opening data space '%s'." , name );
-    }
+    error( "Error while opening data space '%s'." , name );
 
   /* Check data type */
   h_type = H5Dget_type(h_data);
@@ -121,6 +116,7 @@ void readArrayBackEnd(hid_t grp, char* name, enum DATA_TYPE type, int N, int dim
   if(temp == NULL)
     error("Unable to allocate memory for temporary buffer");
 
+  /* Prepare information for hyperslab */
   if(dim > 1)
     {
       rank = 2;
@@ -161,6 +157,9 @@ void readArrayBackEnd(hid_t grp, char* name, enum DATA_TYPE type, int N, int dim
   
   /* Free and close everything */
   free(temp);
+  H5Pclose(h_plist_id);
+  H5Sclose(h_filespace);
+  H5Sclose(h_memspace);
   H5Tclose(h_type);
   H5Dclose(h_data);
 }
@@ -285,10 +284,13 @@ void read_ic_parallel ( char* fileName, double dim[3], struct part **parts,  int
   /* Close particle group */
   H5Gclose(h_grp);
 
-  /* message("Done Reading particles..."); */
+  /* Close property handler */
+  H5Pclose(h_plist_id);
 
   /* Close file */
   H5Fclose(h_file);
+
+  /* message("Done Reading particles..."); */
 }
 
 
-- 
GitLab