Truncating the string was also a red herring. The same executable sometimes works and sometimes doesn't. There's some randomness involved which makes debugging this harder.

One weird observation is that it prints "Deallocated!" before "Caught!" when it does work - that seems like the wrong order.