porting segfault fix (in signal handling) from optimize branch