Stdlib Hashmap error

I am running into an error with the stdlib hashmap routines when the final procedure is run to free memory. I filed an issue on the stdlib repo, link below, but thought a post here might get a little better visibility. Compiler is Intel, both ifort and ifx. Only happens when program is structured so that the final procedure is called. There is a recursive ‘free_map_entry_pool’ that errors with a memory write error.

Here is what I’ve been able to figure out:

  • Generally happens when greater than ~1 million entries in the map.
  • Added some print statements to try to gauge when the error happens, and usually happens after ~6000 or so entries are freed.
  • Removing the deallocate statements stops the error from occurring on ifort in release config only. Still present in debug/release on ifx. (however doesn’t free memory)

Not sure if perhaps the hashmap routines are writing out of bounds somewhere along, or perhaps an issue with recursive routines in the Intel compilers.

https://github.com/fortran-lang/stdlib/issues/750

program hash_error
use stdlib_hashmaps, only: chaining_hashmap_type, open_hashmap_type
use stdlib_hashmap_wrappers, only: fnv_1_hasher, key_type, set
    
implicit none
 
call hash_test

contains

subroutine hash_test
    
    character(len=12) :: char_key
    
    integer :: i, n

    type(key_type) :: key
    type(chaining_hashmap_type) :: test_map
    
    n=1030000
    
    call test_map%init(fnv_1_hasher, 22)

    do i = 1, n
        write (char_key,'(I0)') i
        call set(key, char_key )
        call test_map%map_entry(key)
    enddo
    
end subroutine hash_test
end program

Just to follow up in case others run into this issue. This apparently was a stack overflow issue on Windows, it just didn’t give a stack overflow error. Increasing the stack size for the exe fixed the issue.