Freeing returned strings

Is there a correct way to free strings returned by functions such as H5Tget_member_name which return a char*?

The documentation says that they should be freed after use. That's all well and good until you're using two different memory allocators. For example, I'm currently developing a DLL which calls into the hdf5 libraries. Since I'm developing the dll, I'm in "_DEBUG" mode and using Microsoft's debug memory management. Therefore, if I call free on the returned pointer, it's likely to cause an access violation because the free routine does not match the alloc routine (I'm using the standard library hdf5 library straight from the web).

I found a message to the forum from back in 2009 which is almost certainly the same issue. Unfortunately, no one responded to the poor fellow.

http://hdf-forum.184993.n3.nabble.com/free-buffer-returned-by-H5Tget-member-name-result-in-runtime-error-in-Windows-Vista-tt194656.html

Ideally, there would be a free function exported from the HDF5 library which could be called to properly handle the deallocation. If there is, I haven't found it in the docs. It seems like the proper function (MMfree, or something like that) is #defined to free. Since it's a #define, it doesn't end up helping at all.

Thanks,
Jason

You are quite right, Jason

I also have this problem with the calls from another language - for example,
Delphi.
Thus I always have to add the following code in every new release myself:

Add free memory for functions, returning * char
in:
H5public.h

H5_DLL herr_t H5free_mem(char * memToFree);

in:
H5.c

herr_t
H5free_mem(char * memToFree)
{
    herr_t ret_value = SUCCEED;

    FUNC_ENTER_API(FAIL)
    H5TRACE0("e","");

    /* Free memory */
    free(memToFree);

done:
    FUNC_LEAVE_API(ret_value)
}

It would be nice to have such permanent improvement in version 1.8.12 and
higher.

Regards,
Saulius

···

-----Original Message-----
From: Hdf-forum [mailto:hdf-forum-bounces@lists.hdfgroup.org] On Behalf Of
Jason Sommerville
Sent: Thursday, October 24, 2013 12:15 AM
To: hdf-forum@lists.hdfgroup.org
Subject: [Hdf-forum] Freeing returned strings

Is there a correct way to free strings returned by functions such as
H5Tget_member_name which return a char*?

The documentation says that they should be freed after use. That's all well
and good until you're using two different memory allocators. For example,
I'm currently developing a DLL which calls into the hdf5 libraries. Since
I'm developing the dll, I'm in "_DEBUG" mode and using Microsoft's debug
memory management. Therefore, if I call free on the returned pointer, it's
likely to cause an access violation because the free routine does not match
the alloc routine (I'm using the standard library hdf5 library straight from
the web).

I found a message to the forum from back in 2009 which is almost certainly
the same issue. Unfortunately, no one responded to the poor fellow.

http://hdf-forum.184993.n3.nabble.com/free-buffer-returned-by-H5Tget-member-
name-result-in-runtime-error-in-Windows-Vista-tt194656.html

Ideally, there would be a free function exported from the HDF5 library which
could be called to properly handle the deallocation. If there is, I haven't
found it in the docs. It seems like the proper function (MMfree, or
something like that) is #defined to free. Since it's a #define, it doesn't
end up helping at all.

Thanks,
Jason

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

Jason and Saulius,

I created an issue in JIRA. Sorry, it will not be implemented in 1.8.12, but we will try to address it in the next release.

Elena

···

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Elena Pourmal The HDF Group http://hdfgroup.org
1800 So. Oak St., Suite 203, Champaign IL 61820
217.531.6112
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

On Oct 23, 2013, at 4:39 PM, Saulius Raudeliunas <saulius.raudeliunas@ff.vu.lt> wrote:

You are quite right, Jason

I also have this problem with the calls from another language - for example,
Delphi.
Thus I always have to add the following code in every new release myself:

Add free memory for functions, returning * char
in:
H5public.h

H5_DLL herr_t H5free_mem(char * memToFree);

in:
H5.c

herr_t
H5free_mem(char * memToFree)
{
   herr_t ret_value = SUCCEED;

   FUNC_ENTER_API(FAIL)
   H5TRACE0("e","");

   /* Free memory */
   free(memToFree);

done:
   FUNC_LEAVE_API(ret_value)
}

It would be nice to have such permanent improvement in version 1.8.12 and
higher.

Regards,
Saulius

-----Original Message-----
From: Hdf-forum [mailto:hdf-forum-bounces@lists.hdfgroup.org] On Behalf Of
Jason Sommerville
Sent: Thursday, October 24, 2013 12:15 AM
To: hdf-forum@lists.hdfgroup.org
Subject: [Hdf-forum] Freeing returned strings

Is there a correct way to free strings returned by functions such as
H5Tget_member_name which return a char*?

The documentation says that they should be freed after use. That's all well
and good until you're using two different memory allocators. For example,
I'm currently developing a DLL which calls into the hdf5 libraries. Since
I'm developing the dll, I'm in "_DEBUG" mode and using Microsoft's debug
memory management. Therefore, if I call free on the returned pointer, it's
likely to cause an access violation because the free routine does not match
the alloc routine (I'm using the standard library hdf5 library straight from
the web).

I found a message to the forum from back in 2009 which is almost certainly
the same issue. Unfortunately, no one responded to the poor fellow.

http://hdf-forum.184993.n3.nabble.com/free-buffer-returned-by-H5Tget-member-
name-result-in-runtime-error-in-Windows-Vista-tt194656.html

Ideally, there would be a free function exported from the HDF5 library which
could be called to properly handle the deallocation. If there is, I haven't
found it in the docs. It seems like the proper function (MMfree, or
something like that) is #defined to free. Since it's a #define, it doesn't
end up helping at all.

Thanks,
Jason

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

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

Has this issue been resolved in 1.8.13?

Thanks,
Jason

···

On 10/23/2013 7:21 PM, Elena Pourmal wrote:

Jason and Saulius,

I created an issue in JIRA. Sorry, it will not be implemented in 1.8.12, but we will try to address it in the next release.

Elena
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Elena Pourmal The HDF Group http://hdfgroup.org
1800 So. Oak St., Suite 203, Champaign IL 61820
217.531.6112
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

On Oct 23, 2013, at 4:39 PM, Saulius Raudeliunas > <saulius.raudeliunas@ff.vu.lt <mailto:saulius.raudeliunas@ff.vu.lt>> > wrote:

You are quite right, Jason

I also have this problem with the calls from another language - for example,
Delphi.
Thus I always have to add the following code in every new release myself:

Add free memory for functions, returning * char
in:
H5public.h

H5_DLL herr_t H5free_mem(char * memToFree);

in:
H5.c

herr_t
H5free_mem(char * memToFree)
{
   herr_t ret_value = SUCCEED;

   FUNC_ENTER_API(FAIL)
   H5TRACE0("e","");

   /* Free memory */
   free(memToFree);

done:
   FUNC_LEAVE_API(ret_value)
}

It would be nice to have such permanent improvement in version 1.8.12 and
higher.

Regards,
Saulius

-----Original Message-----
From: Hdf-forum [mailto:hdf-forum-bounces@lists.hdfgroup.org <mailto:forum-bounces@lists.hdfgroup.org>] On Behalf Of
Jason Sommerville
Sent: Thursday, October 24, 2013 12:15 AM
To: hdf-forum@lists.hdfgroup.org <mailto:hdf-forum@lists.hdfgroup.org>
Subject: [Hdf-forum] Freeing returned strings

Is there a correct way to free strings returned by functions such as
H5Tget_member_name which return a char*?

The documentation says that they should be freed after use. That's all well
and good until you're using two different memory allocators. For example,
I'm currently developing a DLL which calls into the hdf5 libraries. Since
I'm developing the dll, I'm in "_DEBUG" mode and using Microsoft's debug
memory management. Therefore, if I call free on the returned pointer, it's
likely to cause an access violation because the free routine does not match
the alloc routine (I'm using the standard library hdf5 library straight from
the web).

I found a message to the forum from back in 2009 which is almost certainly
the same issue. Unfortunately, no one responded to the poor fellow.

http://hdf-forum.184993.n3.nabble.com/free-buffer-returned-by-H5Tget-member-
name-result-in-runtime-error-in-Windows-Vista-tt194656.html

Ideally, there would be a free function exported from the HDF5 library which
could be called to properly handle the deallocation. If there is, I haven't
found it in the docs. It seems like the proper function (MMfree, or
something like that) is #defined to free. Since it's a #define, it doesn't
end up helping at all.

Thanks,
Jason

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

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

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

---
This email is free from viruses and malware because avast! Antivirus protection is active.
http://www.avast.com

http://www.hdfgroup.org/HDF5/doc/RM/RM_H5.html#Library-FreeMemory

···

From: Hdf-forum [mailto:hdf-forum-bounces@lists.hdfgroup.org] On Behalf Of Jason Sommerville
Sent: Friday, September 5, 2014 10:10 AM
To: HDF Users Discussion List
Subject: Re: [Hdf-forum] Freeing returned strings

Has this issue been resolved in 1.8.13?

Thanks,
Jason

On 10/23/2013 7:21 PM, Elena Pourmal wrote:
Jason and Saulius,

I created an issue in JIRA. Sorry, it will not be implemented in 1.8.12, but we will try to address it in the next release.

Elena
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Elena Pourmal The HDF Group http://hdfgroup.org
1800 So. Oak St., Suite 203, Champaign IL 61820
217.531.6112
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

On Oct 23, 2013, at 4:39 PM, Saulius Raudeliunas <saulius.raudeliunas@ff.vu.lt<mailto:saulius.raudeliunas@ff.vu.lt>> wrote:

You are quite right, Jason

I also have this problem with the calls from another language - for example,
Delphi.
Thus I always have to add the following code in every new release myself:

Add free memory for functions, returning * char
in:
H5public.h

H5_DLL herr_t H5free_mem(char * memToFree);

in:
H5.c

herr_t
H5free_mem(char * memToFree)
{
   herr_t ret_value = SUCCEED;

   FUNC_ENTER_API(FAIL)
   H5TRACE0("e","");

   /* Free memory */
   free(memToFree);

done:
   FUNC_LEAVE_API(ret_value)
}

It would be nice to have such permanent improvement in version 1.8.12 and
higher.

Regards,
Saulius

-----Original Message-----
From: Hdf-forum [mailto:hdf-forum-bounces@lists.hdfgroup.org<mailto:forum-bounces@lists.hdfgroup.org>] On Behalf Of
Jason Sommerville
Sent: Thursday, October 24, 2013 12:15 AM
To: hdf-forum@lists.hdfgroup.org<mailto:hdf-forum@lists.hdfgroup.org>
Subject: [Hdf-forum] Freeing returned strings

Is there a correct way to free strings returned by functions such as
H5Tget_member_name which return a char*?

The documentation says that they should be freed after use. That's all well
and good until you're using two different memory allocators. For example,
I'm currently developing a DLL which calls into the hdf5 libraries. Since
I'm developing the dll, I'm in "_DEBUG" mode and using Microsoft's debug
memory management. Therefore, if I call free on the returned pointer, it's
likely to cause an access violation because the free routine does not match
the alloc routine (I'm using the standard library hdf5 library straight from
the web).

I found a message to the forum from back in 2009 which is almost certainly
the same issue. Unfortunately, no one responded to the poor fellow.

http://hdf-forum.184993.n3.nabble.com/free-buffer-returned-by-H5Tget-member-
name-result-in-runtime-error-in-Windows-Vista-tt194656.html

Ideally, there would be a free function exported from the HDF5 library which
could be called to properly handle the deallocation. If there is, I haven't
found it in the docs. It seems like the proper function (MMfree, or
something like that) is #defined to free. Since it's a #define, it doesn't
end up helping at all.

Thanks,
Jason

_______________________________________________
Hdf-forum is for HDF software users discussion.
Hdf-forum@lists.hdfgroup.org<mailto:Hdf-forum@lists.hdfgroup.org>
http://mail.lists.hdfgroup.org/mailman/listinfo/hdf-forum_lists.hdfgroup.org

_______________________________________________
Hdf-forum is for HDF software users discussion.
Hdf-forum@lists.hdfgroup.org<mailto:Hdf-forum@lists.hdfgroup.org>
http://mail.lists.hdfgroup.org/mailman/listinfo/hdf-forum_lists.hdfgroup.org

_______________________________________________

Hdf-forum is for HDF software users discussion.

Hdf-forum@lists.hdfgroup.org<mailto:Hdf-forum@lists.hdfgroup.org>

http://mail.lists.hdfgroup.org/mailman/listinfo/hdf-forum_lists.hdfgroup.org

________________________________
[http://static.avast.com/emails/avast-mail-stamp.png]<http://www.avast.com/>

This email is free from viruses and malware because avast! Antivirus<http://www.avast.com/> protection is active.

Thanks. I was also a little to fast on the e-mail list. I noted that it is the first item in the 1.8.13 changelog. Sorry for the unnecessary traffic!

Thanks,
Jason

···

On 9/5/2014 11:12 AM, Gerd Heber wrote:

http://www.hdfgroup.org/HDF5/doc/RM/RM_H5.html#Library-FreeMemory

*From:*Hdf-forum [mailto:hdf-forum-bounces@lists.hdfgroup.org] *On Behalf Of *Jason Sommerville
*Sent:* Friday, September 5, 2014 10:10 AM
*To:* HDF Users Discussion List
*Subject:* Re: [Hdf-forum] Freeing returned strings

Has this issue been resolved in 1.8.13?

Thanks,
Jason

On 10/23/2013 7:21 PM, Elena Pourmal wrote:

    Jason and Saulius,

    I created an issue in JIRA. Sorry, it will not be implemented in
    1.8.12, but we will try to address it in the next release.

    Elena

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    Elena Pourmal The HDF Group http://hdfgroup.org
    1800 So. Oak St., Suite 203, Champaign IL 61820
    217.531.6112
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    On Oct 23, 2013, at 4:39 PM, Saulius Raudeliunas > <saulius.raudeliunas@ff.vu.lt > <mailto:saulius.raudeliunas@ff.vu.lt>> wrote:

        You are quite right, Jason

        I also have this problem with the calls from another language
        - for example,
        Delphi.
        Thus I always have to add the following code in every new
        release myself:

        Add free memory for functions, returning * char
        in:
        H5public.h

        H5_DLL herr_t H5free_mem(char * memToFree);

        in:
        H5.c

        herr_t
        H5free_mem(char * memToFree)
        {
           herr_t ret_value = SUCCEED;

           FUNC_ENTER_API(FAIL)
           H5TRACE0("e","");

           /* Free memory */
           free(memToFree);

        done:
           FUNC_LEAVE_API(ret_value)
        }

        It would be nice to have such permanent improvement in version
        1.8.12 and
        higher.

        Regards,
        Saulius

        -----Original Message-----
        From: Hdf-forum [mailto:hdf-forum-bounces@lists.hdfgroup.org
        <mailto:forum-bounces@lists.hdfgroup.org>] On Behalf Of
        Jason Sommerville
        Sent: Thursday, October 24, 2013 12:15 AM
        To: hdf-forum@lists.hdfgroup.org
        <mailto:hdf-forum@lists.hdfgroup.org>
        Subject: [Hdf-forum] Freeing returned strings

        Is there a correct way to free strings returned by functions
        such as
        H5Tget_member_name which return a char*?

        The documentation says that they should be freed after use.
        That's all well
        and good until you're using two different memory allocators.
        For example,
        I'm currently developing a DLL which calls into the hdf5
        libraries. Since
        I'm developing the dll, I'm in "_DEBUG" mode and using
        Microsoft's debug
        memory management. Therefore, if I call free on the returned
        pointer, it's
        likely to cause an access violation because the free routine
        does not match
        the alloc routine (I'm using the standard library hdf5 library
        straight from
        the web).

        I found a message to the forum from back in 2009 which is
        almost certainly
        the same issue. Unfortunately, no one responded to the poor
        fellow.

        http://hdf-forum.184993.n3.nabble.com/free-buffer-returned-by-H5Tget-member-
        name-result-in-runtime-error-in-Windows-Vista-tt194656.html

        Ideally, there would be a free function exported from the HDF5
        library which
        could be called to properly handle the deallocation. If there
        is, I haven't
        found it in the docs. It seems like the proper function
        (MMfree, or
        something like that) is #defined to free. Since it's a
        #define, it doesn't
        end up helping at all.

        Thanks,
        Jason

        _______________________________________________
        Hdf-forum is for HDF software users discussion.
        Hdf-forum@lists.hdfgroup.org <mailto:Hdf-forum@lists.hdfgroup.org>
        http://mail.lists.hdfgroup.org/mailman/listinfo/hdf-forum_lists.hdfgroup.org

        _______________________________________________
        Hdf-forum is for HDF software users discussion.
        Hdf-forum@lists.hdfgroup.org <mailto:Hdf-forum@lists.hdfgroup.org>
        http://mail.lists.hdfgroup.org/mailman/listinfo/hdf-forum_lists.hdfgroup.org

    _______________________________________________

    Hdf-forum is for HDF software users discussion.

    Hdf-forum@lists.hdfgroup.org <mailto:Hdf-forum@lists.hdfgroup.org>

    http://mail.lists.hdfgroup.org/mailman/listinfo/hdf-forum_lists.hdfgroup.org

------------------------------------------------------------------------

<http://www.avast.com/>

This email is free from viruses and malware because avast! Antivirus <http://www.avast.com/> protection is active.

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

---
This email is free from viruses and malware because avast! Antivirus protection is active.
http://www.avast.com