Is closing negative hid_t good or bad?

Hi,

This is perhaps a silly question, but if I create a resource, say:

hid_t did = H5Dopen( loc_id, "data" );

and then test,

if (did >= 0) {

}

does it matter if I put the H5Dclose inside or outside the if-block?
Does one leak resources in the case where did < 0 and the did is not
closed? And, is the behavior the same for all the HDF api functions? I
did not see any specific mention in the docs.

Matt

Hi Matt,

···

On Sep 1, 2010, at 9:56 AM, Matt Calder wrote:

Hi,

This is perhaps a silly question, but if I create a resource, say:

hid_t did = H5Dopen( loc_id, "data" );

and then test,

if (did >= 0) {

}

does it matter if I put the H5Dclose inside or outside the if-block?
Does one leak resources in the case where did < 0 and the did is not
closed? And, is the behavior the same for all the HDF api functions? I
did not see any specific mention in the docs.

  If H5Dopen (or any other function which returns an ID) fails (and returns a negative value), the HDF5 library will not leak resources. BTW, the [negative] ID value returned when one of these routines fails would be rejected by the object close routine. It's analogous to malloc() returning NULL, you can't pass NULL into free().

  Quincey

Thanks Quincey,

I have been assuming this, but I had a sudden attack of doubt.

Matt

···

On Wed, Sep 1, 2010 at 11:01 AM, Quincey Koziol <koziol@hdfgroup.org> wrote:

Hi Matt,

On Sep 1, 2010, at 9:56 AM, Matt Calder wrote:

Hi,

This is perhaps a silly question, but if I create a resource, say:

hid_t did = H5Dopen( loc_id, "data" );

and then test,

if (did >= 0) {

}

does it matter if I put the H5Dclose inside or outside the if-block?
Does one leak resources in the case where did < 0 and the did is not
closed? And, is the behavior the same for all the HDF api functions? I
did not see any specific mention in the docs.

   If H5Dopen \(or any other function which returns an ID\) fails \(and returns a negative value\), the HDF5 library will not leak resources\.  BTW, the \[negative\] ID value returned when one of these routines fails would be rejected by the object close routine\.  It&#39;s analogous to malloc\(\) returning NULL, you can&#39;t pass NULL into free\(\)\.

   Quincey

_______________________________________________
Hdf-forum is for HDF software users discussion.
Hdf-forum@hdfgroup.org
http://mail.hdfgroup.org/mailman/listinfo/hdf-forum_hdfgroup.org