What is surprising, is that the patch you proposed does seem to eliminate
the bug on your system. Please check well though, because I did notice
some change in the behaviour of TeXmacs. For instance, TeXmacs does not
automatically crash at the first autosave, but only after typing a bit.
You may also try to add a line "rep = NULL" at the end of destroy_tree_rep
in order to check whether this also stabilizes TeXmacs on your system...
In fact, the bug seems to be related to some kind of memory corruption.
Another approach might be to determine which memory location
is corrupted and then try to track down where in the code this happens.
It may be some very dumb compilation error in some not-too-often used routine.
I do not know any debugging tool which allows you to do this though.