Shared library code crashing, but only from REPL

I am calling a Fortran shared library in my program.

If I run my Julia program (which calls the Fortran library) everything runs as expected.

However, if I run exactly the same code in the Julia REPL (connected to Visual Studio Code on Linux) then it fails and reports “ERROR: StackOverflowError:”. This error is being reported from Julia, and not from the Fortran library. I get exactly the same error when I build the Fortran library with both ifort and gfortran.

I don’t really have a good idea how to try and debug this REPL-only crash. Is there a reason why the code is behaving differently when called from the REPL?