I remember a similar problem posted some time ago about the result variable of allocatable character string (with OpenMP, replied by @martin with a link to the bug report 113797)
If this may be related, the runtime error I encountered above might also be a result / side effect of the same possible bug… (but here without OpenMP). FWIW, the last part of the above bug report says:
typedef character(kind=1) struct character(kind=1)[1:slen.1][1:slen.1]; pstr.2 = 0B; slen.1 = 0;
Maybe the order here. slen.1 should be set to 0 before the use inside the typedef.
That is kinda of the reason why static works (with not openmp)
Also FWIW, I’ve tried changing the main program to a subroutine (to avoid the complication of the main program), and “-fsanitize=address” gave a memory leak of >1300 bytes.
A workaround might be to wrap the allocatable string to a derived type (like “variable string”) and use it throughout (including the result variables), or more conveniently, use some existing library for a wrapped string type, but the possible compiler bug above (not sure yet) remains…