https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67950
--- Comment #5 from Hans Streibel <streibel.2003 at gmx dot net> --- Just noticed: Adding an optimization flag -O1 or -O2 to g++ removes this bug (-O0 does not help): [root@dev71 tmp]# /opt/gcc-4.9.3-hans/bin/g++ -o tcpserver.4.9.3++ -O1 -Wall tcpserver.c [root@dev71 tmp]# ./tcpserver.4.9.3++ 1234 --> before accept() <-- --> accept() returned: 4 <-- fd after accept(): 4 abc read 0 bytes from the socket. Socket is closed --> before accept() <--