diff --git a/tests/regress/segfault_on_stop.py b/tests/regress/segfault_on_stop.py new file mode 100755 index 00000000..8d577109 --- /dev/null +++ b/tests/regress/segfault_on_stop.py @@ -0,0 +1,13 @@ +#!/usr/bin/env python + +import regress +import unicorn + + +class SegfaultOnStop(regress.RegressTest): + def test(self): + unicorn.Uc(unicorn.UC_ARCH_X86, unicorn.UC_MODE_64).emu_stop() + self.assertTrue(True, "If not reached, then we have a crashing bug.") + +if __name__ == '__main__': + regress.main() diff --git a/uc.c b/uc.c index 00efc805..e3107b70 100644 --- a/uc.c +++ b/uc.c @@ -525,8 +525,10 @@ uc_err uc_emu_stop(uc_engine *uc) return UC_ERR_OK; uc->stop_request = true; - // exit the current TB - cpu_exit(uc->current_cpu); + if (uc->current_cpu) { + // exit the current TB + cpu_exit(uc->current_cpu); + } return UC_ERR_OK; }