That error message usually means that memory which was allocated by one thread was freed by another thread. This usually occurs if an XS-based module is not written to be thread-safe, or is buggy. Less commonly in recent perls, it may indicate a bug in perl itself.
The usual way to debug such things is to set a breakpoint at the place in the src where the error is is tested for and raised, to see what address is being freed, and by what. Then re-run with a conditiomnal breakpoint set in the allocation code to see where that address is allocated.
Run gdb with PERL_HASH_SEED=0 to get consistent results between runs.
Dave.