The ecases_remove_by_expi() function in expect.c uses memcpy() to shift elements down. The areas can be overlapping. When they are, the construct is non-portable and can lead to memory corruption.
Please replace the memcpy call with a memmove call. That fixes the issue.
This is a real problem. It causes expect to randomly crash when run on the LysKOM server testsuite on an x86_64 Linux system (Ubuntu 13.04, gcc 4.7.3). valgrind helped me track down the issue.
(The issue can be reproduced by running the test suite of https://git.lysator.liu.se/lyskom-server/lyskom-server. Be sure to instrument runtest so that it uses valgrind to invoce expect.)
The enclosed file is a minimal example that demonstrates the issue. If you run it as "valgrind expect trigger2.expect", valgrind will report an error similar to:
The expect5.45-memmove.patch previoiusly attached to this issue fixes the problem.
Committed to CVS.
Thank you for the report and fix.