changed epspml and muinv to malloc OUTSIDE the functions. Also found exact problem: when I malloc both at the same time, I get the bug, but not when I malloc them separately.