Works as expected:
gcc tty_crash.cc -I deps/libuv/include -L deps/libuv/out/Debug -luv && ./a.outCrashes with various errors, bus errors/segmentation faults/SIGABRT:
gcc tty_crash.cc -I deps/libuv/include -L deps/libuv/out/Debug -luv -D CRASHING && ./a.outAccording to gdb it's crashing on the QUEUE_REMOVE line in unix/stream.c:
static void uv__write_callbacks(uv_stream_t* stream) {
uv_write_t* req;
QUEUE* q;
while (!QUEUE_EMPTY(&stream->write_completed_queue)) {
/* Pop a req off write_completed_queue. */
q = QUEUE_HEAD(&stream->write_completed_queue);
req = QUEUE_DATA(q, uv_write_t, queue);
QUEUE_REMOVE(q); // <-- here
uv__req_unregister(stream->loop, req);
Accidentally I came across this issue. In case you didn't find out what the problem was, the issue is with the local variables defined in the
ttyThingfunction. As they're allocated in the stack, as soon as the function exists they cease to exist. Declaring:globally fixes the issue.