That's a tricky one. The "gmp" library is used for multiprecision arithmetic, and is called both by the "factory" library and directly by the rest of Macaulay2. Up to version 1.3.1 of Macaulay2, but not in the current source code in the repository, "factory" and the rest of Macaulay2 used different memory allocators. Since "gmp" allocates memory, it has to be told which allocator to use, so every time we enter or leave a section of code, we tell "gmp" what to do. In addition, we have a constructor that runs very early that tells gmp to use our_gmp_default_allocate, which prints that error message and terminates the program. The idea is to indicate that gmp has been called without being properly told yet which allocator to use.
Have you compiled the program yourself? If so, have you changed the order of *.o files on the link line? That could affect the order of constructor execution. But it's hard to understand why that error would occur only when M2 is run by M2 to execute example code in the production of documentation. Can you switch to the current source code?