xseg_leave: Make it reentrant and thread-safe