H5cpp resource leak

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

H5cpp resource leak

Thomas Krijnen
Hi,

I have observed the following code leaks resources linearly with program runtime (admittedly I checked only 1.8.19, but didn't see a reference to this in the .20 release notes).

int main(int, char**) {
    H5::CompType ct((size_t)8);
    ct.insertMember("a", 0, H5::PredType::NATIVE_INT32);
    ct.insertMember("b", 4, H5::PredType::NATIVE_INT32);

    for (int i = 0; i < 100000; ++i) {
        H5::IntType dt = ct.getMemberIntType(0);
        std::cerr << dt.getSize(); // just some side effect in order not be optimized away (I doubt it would though)
        dt.close();
    }
}

In my naive understanding this is due to the duplicate reference to p_get_member_type() in:

IntType CompType::getMemberIntType(unsigned member_num) const
{
    try {
      IntType inttype(p_get_member_type(member_num));
        f_DataType_setId(&inttype, p_get_member_type(member_num));
        return(inttype);
    }
    catch (DataTypeIException& E) {
        throw DataTypeIException("CompType::getMemberIntType", E.getDetailMsg());
    }
}

This then results in two identifiers of which only one can be close()d. Note that this is not specific to integer member types.

If one insists on using the C++ types, creating member types in the following fashion enabled me to close resources properly.

H5::IntType dt(H5Tget_member_type(ct.getId(), 0));
std::cerr << dt.getSize();
H5Idec_ref(dt.getId());
dt.close();

Kind regards,
Thomas


_______________________________________________
Hdf-forum is for HDF software users discussion.
[hidden email]
http://lists.hdfgroup.org/mailman/listinfo/hdf-forum_lists.hdfgroup.org
Twitter: https://twitter.com/hdf5
Reply | Threaded
Open this post in threaded view
|

Re: H5cpp resource leak

Binh-Minh Ribler

Hi Thomas,


Thank you for your report of the issue.  It will be addressed in the next release.


Binh-Minh



From: Hdf-forum <[hidden email]> on behalf of Thomas Krijnen <t.krijnen+[hidden email]>
Sent: Monday, December 4, 2017 9:52 AM
To: [hidden email]
Subject: [Hdf-forum] H5cpp resource leak
 
Hi,

I have observed the following code leaks resources linearly with program runtime (admittedly I checked only 1.8.19, but didn't see a reference to this in the .20 release notes).

int main(int, char**) {
    H5::CompType ct((size_t)8);
    ct.insertMember("a", 0, H5::PredType::NATIVE_INT32);
    ct.insertMember("b", 4, H5::PredType::NATIVE_INT32);

    for (int i = 0; i < 100000; ++i) {
        H5::IntType dt = ct.getMemberIntType(0);
        std::cerr << dt.getSize(); // just some side effect in order not be optimized away (I doubt it would though)
        dt.close();
    }
}

In my naive understanding this is due to the duplicate reference to p_get_member_type() in:

IntType CompType::getMemberIntType(unsigned member_num) const
{
    try {
      IntType inttype(p_get_member_type(member_num));
        f_DataType_setId(&inttype, p_get_member_type(member_num));
        return(inttype);
    }
    catch (DataTypeIException& E) {
        throw DataTypeIException("CompType::getMemberIntType", E.getDetailMsg());
    }
}

This then results in two identifiers of which only one can be close()d. Note that this is not specific to integer member types.

If one insists on using the C++ types, creating member types in the following fashion enabled me to close resources properly.

H5::IntType dt(H5Tget_member_type(ct.getId(), 0));
std::cerr << dt.getSize();
H5Idec_ref(dt.getId());
dt.close();

Kind regards,
Thomas


_______________________________________________
Hdf-forum is for HDF software users discussion.
[hidden email]
http://lists.hdfgroup.org/mailman/listinfo/hdf-forum_lists.hdfgroup.org
Twitter: https://twitter.com/hdf5
Reply | Threaded
Open this post in threaded view
|

Re: H5cpp resource leak

Thomas Krijnen
Hi Binh-Minh,

Wonderful, thanks for all the good work.

Kind regards,
Thomas

On Mon, Dec 4, 2017 at 4:49 PM, Binh-Minh Ribler <[hidden email]> wrote:

Hi Thomas,


Thank you for your report of the issue.  It will be addressed in the next release.


Binh-Minh



From: Hdf-forum <[hidden email]> on behalf of Thomas Krijnen <[hidden email]>
Sent: Monday, December 4, 2017 9:52 AM
To: [hidden email]
Subject: [Hdf-forum] H5cpp resource leak
 
Hi,

I have observed the following code leaks resources linearly with program runtime (admittedly I checked only 1.8.19, but didn't see a reference to this in the .20 release notes).

int main(int, char**) {
    H5::CompType ct((size_t)8);
    ct.insertMember("a", 0, H5::PredType::NATIVE_INT32);
    ct.insertMember("b", 4, H5::PredType::NATIVE_INT32);

    for (int i = 0; i < 100000; ++i) {
        H5::IntType dt = ct.getMemberIntType(0);
        std::cerr << dt.getSize(); // just some side effect in order not be optimized away (I doubt it would though)
        dt.close();
    }
}

In my naive understanding this is due to the duplicate reference to p_get_member_type() in:

IntType CompType::getMemberIntType(unsigned member_num) const
{
    try {
      IntType inttype(p_get_member_type(member_num));
        f_DataType_setId(&inttype, p_get_member_type(member_num));
        return(inttype);
    }
    catch (DataTypeIException& E) {
        throw DataTypeIException("CompType::getMemberIntType", E.getDetailMsg());
    }
}

This then results in two identifiers of which only one can be close()d. Note that this is not specific to integer member types.

If one insists on using the C++ types, creating member types in the following fashion enabled me to close resources properly.

H5::IntType dt(H5Tget_member_type(ct.getId(), 0));
std::cerr << dt.getSize();
H5Idec_ref(dt.getId());
dt.close();

Kind regards,
Thomas


_______________________________________________
Hdf-forum is for HDF software users discussion.
[hidden email]
http://lists.hdfgroup.org/mailman/listinfo/hdf-forum_lists.hdfgroup.org
Twitter: https://twitter.com/hdf5


_______________________________________________
Hdf-forum is for HDF software users discussion.
[hidden email]
http://lists.hdfgroup.org/mailman/listinfo/hdf-forum_lists.hdfgroup.org
Twitter: https://twitter.com/hdf5