- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
I have a crash during deallocation of a derived type. I found a thread that may describe a relevant debugging step for me:
community.intel.com/t5/Intel-Fortran-Compiler/heap-corruption-error/m-p/890765#M78197
My question is: how to do the same (find the hidden allocation header) for a derived type instead of an array? For the array it was done by associating a pointer to just after the last element.
[edit to make a proper link]
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
LOC(yourUDT) will give you the address of the data portion of the UDT. Preceding this will be one or more pointer sized elements for the allocation header. What is present, depends on the heap manager. There is at least one for a link, potentially a second for count (in case of array), potentially a third for padding (in case of aligned allocation), possibly a fourth for debugging, ...
You may have to experiment to figure out the header.
Also, the heap manager (unless the TBB scalable allocator is used) is the CRT library heap. You can link in the debug version of the heap and then use the C heap diagnostic functions. See:
https://learn.microsoft.com/en-us/cpp/c-runtime-library/crt-debug-heap-details?view=msvc-170
https://dmalloc.com/ (I havn't seen usages of this)
https://learn.microsoft.com/en-us/cpp/c-runtime-library/reference/heapchk?view=msvc-170
https://learn.microsoft.com/en-us/cpp/c-runtime-library/reference/heapwalk?view=msvc-170
Jim Dempsey
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks.
I was able to print out the integer values of the allocation header elements by defining the variables
INTEGER(KIND=INT_PTR_KIND()) :: iAllocHeader
INTEGER(KIND=INT_PTR_KIND()) :: allocHeader
POINTER (iAllocHeader, allocHeader)
Then print out values for n = 1,2,... by
iAllocHeader = LOC(myObject) - INT_PTR_KIND() * n
write(*,*) "Allocation header",allocHeader
I could see that the value for n=3 was changing slightly at some point, but other objects that deallocate without problem also had a change on this on. Other values were not changing.
I'll probably have to look at your links to check the heap more thoroughly.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Also, make sure you do a Debug build with all build and runtime diagnostics enabled.
Jim Dempsey
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I have done that too, also with another compiler which is generally very good at catching memory issues, but it works fine in the debug build
![](/skins/images/45C6C2D737ED71F4C51F0145C8CB1E9C/responsive_peak/images/icon_anonymous_message.png)
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page