summaryrefslogtreecommitdiffstats
path: root/hl
diff options
context:
space:
mode:
authorPedro Vicente Nunes <pvn@hdfgroup.org>2006-11-14 19:48:58 (GMT)
committerPedro Vicente Nunes <pvn@hdfgroup.org>2006-11-14 19:48:58 (GMT)
commitae7115a9908d35ce6f39aeed0eab900bcc5e1894 (patch)
treeb3755f2b1fe6eac039f46cb2369249cfd53fd720 /hl
parenta9397f3f512d7ade2af548fe3323a474fa48267d (diff)
downloadhdf5-ae7115a9908d35ce6f39aeed0eab900bcc5e1894.zip
hdf5-ae7115a9908d35ce6f39aeed0eab900bcc5e1894.tar.gz
hdf5-ae7115a9908d35ce6f39aeed0eab900bcc5e1894.tar.bz2
[svn-r12913] An attribute was not being closed in H5IMlink_palette
Diffstat (limited to 'hl')
-rw-r--r--hl/src/H5IM.c294
1 files changed, 137 insertions, 157 deletions
diff --git a/hl/src/H5IM.c b/hl/src/H5IM.c
index 12269c4..060387c 100644
--- a/hl/src/H5IM.c
+++ b/hl/src/H5IM.c
@@ -522,7 +522,6 @@ herr_t H5IMlink_palette( hid_t loc_id,
const char *pal_name )
{
-
hid_t image_id;
hid_t attr_type;
hid_t attr_id;
@@ -547,10 +546,12 @@ herr_t H5IMlink_palette( hid_t loc_id,
/* Try to find the attribute "PALETTE" on the >>image<< dataset */
ok_pal = H5LT_find_attribute( image_id, "PALETTE" );
- /* It does not exist. We create the attribute and one reference */
+/*-------------------------------------------------------------------------
+ * It does not exist. We create the attribute and one reference
+ *-------------------------------------------------------------------------
+ */
if ( ok_pal == 0 )
{
-
if ( (attr_space_id = H5Screate( H5S_SCALAR )) < 0 )
goto out;
@@ -570,85 +571,82 @@ herr_t H5IMlink_palette( hid_t loc_id,
if ( H5Awrite( attr_id, attr_type, &ref ) < 0 )
goto out;
+ /* close */
if ( H5Sclose( attr_space_id ) < 0 )
goto out;
+ if ( H5Tclose( attr_type ) < 0 )
+ goto out;
+ if ( H5Aclose( attr_id ) < 0 )
+ goto out;
}
- /* The attribute already exists, open it */
-
+/*-------------------------------------------------------------------------
+ * The attribute already exists, open it
+ *-------------------------------------------------------------------------
+ */
else if ( ok_pal == 1 )
-
+
{
-
if ( (attr_id = H5Aopen_name( image_id, "PALETTE" )) < 0 )
goto out;
-
+
if ( (attr_type = H5Aget_type( attr_id )) < 0 )
goto out;
-
+
if ( (attr_class = H5Tget_class( attr_type )) < 0 )
goto out;
-
- /* Check if it is really a reference */
-
- if ( attr_class == H5T_REFERENCE )
- {
-
- /* Get and save the old reference(s) */
-
- if ( (attr_space_id = H5Aget_space( attr_id )) < 0 )
- goto out;
-
- n_refs = H5Sget_simple_extent_npoints( attr_space_id );
-
- dim_ref = n_refs + 1;
-
- refbuf = malloc( sizeof(hobj_ref_t) * (int)dim_ref );
-
- if ( H5Aread( attr_id, attr_type, refbuf ) < 0 )
- goto out;
-
- if ( H5Sclose( attr_space_id ) < 0 )
- goto out;
-
- /* The attribute must be deleted, in order to the new one can reflect the changes*/
- if ( H5Adelete( image_id, "PALETTE" ) < 0 )
- goto out;
-
- /* Create a new reference for this palette. */
- if ( H5Rcreate( &ref, loc_id, pal_name, H5R_OBJECT, -1 ) < 0 )
- goto out;
-
- refbuf[n_refs] = ref;
-
- /* Create the data space for the new references */
- if ( (attr_space_id = H5Screate_simple( 1, &dim_ref, NULL )) < 0 )
- goto out;
-
- /* Create the attribute again with the changes of space */
- if ( (attr_id = H5Acreate( image_id, "PALETTE", attr_type, attr_space_id, H5P_DEFAULT )) < 0 )
- goto out;
-
- /* Write the attribute with the new references */
- if ( H5Awrite( attr_id, attr_type, refbuf ) < 0 )
- goto out;
-
- if ( H5Sclose( attr_space_id ) < 0 )
- goto out;
-
- free( refbuf );
-
- } /* H5T_REFERENCE */
-
- if ( H5Tclose( attr_type ) < 0 )
+
+ /* Get and save the old reference(s) */
+ if ( (attr_space_id = H5Aget_space( attr_id )) < 0 )
goto out;
-
- /* Close the attribute. */
+
+ n_refs = H5Sget_simple_extent_npoints( attr_space_id );
+
+ dim_ref = n_refs + 1;
+
+ refbuf = malloc( sizeof(hobj_ref_t) * (int)dim_ref );
+
+ if ( H5Aread( attr_id, attr_type, refbuf ) < 0 )
+ goto out;
+
+ /* The attribute must be deleted, in order to the new one can reflect the changes*/
+ if ( H5Adelete( image_id, "PALETTE" ) < 0 )
+ goto out;
+
+ /* Create a new reference for this palette. */
+ if ( H5Rcreate( &ref, loc_id, pal_name, H5R_OBJECT, -1 ) < 0 )
+ goto out;
+
+ refbuf[n_refs] = ref;
+
+ /* Create the data space for the new references */
+ if ( H5Sclose( attr_space_id ) < 0 )
+ goto out;
+
+ if ( (attr_space_id = H5Screate_simple( 1, &dim_ref, NULL )) < 0 )
+ goto out;
+
+ /* Create the attribute again with the changes of space */
if ( H5Aclose( attr_id ) < 0 )
goto out;
- }
+ if ( (attr_id = H5Acreate( image_id, "PALETTE", attr_type, attr_space_id, H5P_DEFAULT )) < 0 )
+ goto out;
+
+ /* Write the attribute with the new references */
+ if ( H5Awrite( attr_id, attr_type, refbuf ) < 0 )
+ goto out;
+
+ /* close */
+ if ( H5Sclose( attr_space_id ) < 0 )
+ goto out;
+ if ( H5Aclose( attr_id ) < 0 )
+ goto out;
+
+ free( refbuf );
+
+ } /* ok_pal == 1 */
/* Close the image dataset. */
if ( H5Dclose( image_id ) < 0 )
@@ -658,6 +656,9 @@ herr_t H5IMlink_palette( hid_t loc_id,
out:
H5Dclose( image_id );
+ H5Sclose( attr_space_id );
+ H5Tclose( attr_type );
+ H5Aclose( attr_id );
return -1;
}
@@ -884,92 +885,80 @@ herr_t H5IMget_palette_info( hid_t loc_id,
hid_t pal_id;
hid_t pal_space_id;
hsize_t pal_maxdims[2];
-
+
/* Open the dataset. */
if ( (image_id = H5Dopen( loc_id, image_name )) < 0 )
return -1;
-
+
/* Try to find the attribute "PALETTE" on the >>image<< dataset */
has_pal = H5IM_find_palette( image_id );
-
+
if ( has_pal == 1 )
{
-
if ( (attr_id = H5Aopen_name( image_id, "PALETTE" )) < 0 )
goto out;
-
+
if ( (attr_type = H5Aget_type( attr_id )) < 0 )
goto out;
-
+
if ( (attr_class = H5Tget_class( attr_type )) < 0 )
goto out;
-
- /* Check if it is really a reference */
-
- if ( attr_class == H5T_REFERENCE )
- {
-
- /* Get the reference(s) */
-
- if ( (attr_space_id = H5Aget_space( attr_id )) < 0 )
- goto out;
-
- n_refs = H5Sget_simple_extent_npoints( attr_space_id );
-
- dim_ref = n_refs;
-
- refbuf = malloc( sizeof(hobj_ref_t) * (int)dim_ref );
-
- if ( H5Aread( attr_id, attr_type, refbuf ) < 0 )
- goto out;
-
- /* Get the actual palette */
-
+
+ /* Get the reference(s) */
+ if ( (attr_space_id = H5Aget_space( attr_id )) < 0 )
+ goto out;
+
+ n_refs = H5Sget_simple_extent_npoints( attr_space_id );
+
+ dim_ref = n_refs;
+
+ refbuf = malloc( sizeof(hobj_ref_t) * (int)dim_ref );
+
+ if ( H5Aread( attr_id, attr_type, refbuf ) < 0 )
+ goto out;
+
+ /* Get the actual palette */
if ( (pal_id = H5Rdereference( image_id, H5R_OBJECT, &refbuf[pal_number] )) < 0 )
- goto out;
-
+ goto out;
+
if ( (pal_space_id = H5Dget_space( pal_id )) < 0 )
goto out;
-
+
if ( H5Sget_simple_extent_ndims( pal_space_id ) < 0 )
goto out;
-
+
if ( H5Sget_simple_extent_dims( pal_space_id, pal_dims, pal_maxdims ) < 0 )
goto out;
-
+
+ /* close */
+ if (H5Dclose(pal_id)<0)
+ goto out;
if ( H5Sclose( pal_space_id ) < 0 )
goto out;
-
if ( H5Sclose( attr_space_id ) < 0 )
goto out;
-
- /* close the dereferenced dataset */
- if (H5Dclose(pal_id)<0)
- goto out;
-
- free( refbuf );
-
- } /* H5T_REFERENCE */
-
if ( H5Tclose( attr_type ) < 0 )
goto out;
-
- /* Close the attribute. */
if ( H5Aclose( attr_id ) < 0 )
goto out;
-
+ free( refbuf );
+
+
}
-
- /* Close the image dataset. */
+
+ /* Close the image dataset. */
if ( H5Dclose( image_id ) < 0 )
return -1;
-
+
return 0;
-
+
out:
H5Dclose( image_id );
+ H5Sclose( attr_space_id );
+ H5Tclose( attr_type );
+ H5Aclose( attr_id );
return -1;
-
+
}
@@ -1018,58 +1007,46 @@ herr_t H5IMget_palette( hid_t loc_id,
if ( has_pal == 1 )
{
-
if ( (attr_id = H5Aopen_name( image_id, "PALETTE" )) < 0 )
goto out;
-
+
if ( (attr_type = H5Aget_type( attr_id )) < 0 )
goto out;
-
+
if ( (attr_class = H5Tget_class( attr_type )) < 0 )
goto out;
+
+ /* Get the reference(s) */
+ if ( (attr_space_id = H5Aget_space( attr_id )) < 0 )
+ goto out;
+
+ n_refs = H5Sget_simple_extent_npoints( attr_space_id );
+
+ dim_ref = n_refs;
+
+ refbuf = malloc( sizeof(hobj_ref_t) * (int)dim_ref );
+
+ if ( H5Aread( attr_id, attr_type, refbuf ) < 0 )
+ goto out;
+
+ /* Get the palette id */
+ if ( (pal_id = H5Rdereference( image_id, H5R_OBJECT, &refbuf[pal_number] )) < 0 )
+ goto out;
+
+ /* Read the palette dataset */
+ if ( H5Dread( pal_id, H5Dget_type(pal_id), H5S_ALL, H5S_ALL, H5P_DEFAULT, pal_data ) < 0 )
+ goto out;
- /* Check if it is really a reference */
- if ( attr_class == H5T_REFERENCE )
- {
-
- /* Get the reference(s) */
- if ( (attr_space_id = H5Aget_space( attr_id )) < 0 )
- goto out;
-
- n_refs = H5Sget_simple_extent_npoints( attr_space_id );
-
- dim_ref = n_refs;
-
- refbuf = malloc( sizeof(hobj_ref_t) * (int)dim_ref );
-
- if ( H5Aread( attr_id, attr_type, refbuf ) < 0 )
- goto out;
-
- /* Get the palette id */
- if ( (pal_id = H5Rdereference( image_id, H5R_OBJECT, &refbuf[pal_number] )) < 0 )
- goto out;
-
- /* Read the palette dataset */
- if ( H5Dread( pal_id, H5Dget_type(pal_id), H5S_ALL, H5S_ALL, H5P_DEFAULT, pal_data ) < 0 )
- goto out;
-
- if ( H5Sclose( attr_space_id ) < 0 )
- goto out;
-
- /* close the dereferenced dataset */
- if (H5Dclose(pal_id)<0)
- goto out;
-
- free( refbuf );
-
- } /* H5T_REFERENCE */
-
+ /* close */
+ if (H5Dclose(pal_id)<0)
+ goto out;
+ if ( H5Sclose( attr_space_id ) < 0 )
+ goto out;
if ( H5Tclose( attr_type ) < 0 )
goto out;
-
- /* Close the attribute. */
if ( H5Aclose( attr_id ) < 0 )
goto out;
+ free( refbuf );
}
/* Close the image dataset. */
@@ -1080,6 +1057,9 @@ herr_t H5IMget_palette( hid_t loc_id,
out:
H5Dclose( image_id );
+ H5Sclose( attr_space_id );
+ H5Tclose( attr_type );
+ H5Aclose( attr_id );
return -1;
}