| |
| Posted by Steven Schveighoffer in reply to eugene | PermalinkReply |
|
Steven Schveighoffer
Posted in reply to eugene
| On 9/14/21 7:31 AM, eugene wrote:
> On Monday, 13 September 2021 at 17:18:30 UTC, eugene wrote:
> Then after pressing ^C (SIGINT) the program gets SIGSEGV, since references to sg0 and sg1 are no longer valid (they are "sitting" in epoll_event structure).
... forget to mention, crashes here:
bool wait() {
const int maxEvents = 8;
EpollEvent[maxEvents] events;
if (done)
return false;
int n = epoll_wait(id, events.ptr, maxEvents, -1);
if (-1 == n)
return false;
foreach (k; 0 .. n) {
EventSource s = events[k].es;
ulong ecode = s.eventCode(events[k].event_mask); // <<<<< SIGSEGV
sg0/sg1 are destroyed, so s points to wrong location.
Note that s likely still points at a valid memory address. However, when an object is destroyed, its vtable is nulled out (precisely to cause a segfault if you try to use an already-freed object). There is also the possibility the memory block has been reallocated to something else, and that is causing the segfault. But if the segfault is consistent, most likely it's the former problem.
-Steve
|