Concurrent calls to rig_debug() could use the same temporary buffer and corrupt the saved debug history. Give each call its own buffer and update the shared history under the existing mutex.