Describe the bug

In src/anet.c, line 503, _anetTcpServer will call anetV6Only. If it failed in setsockopt at line 471, it will close the socket and goto label error at line 513 without change socket to -1. Suppose that we do not support IPV6 Protocol, and we create a socket, then it will be closed. And at the "error" label, it will be closed twice and return a errno EBADF, which will cause failure to create any tcp server.

To reproduce

  1. Use lwip (https://git.savannah.nongnu.org/cgit/lwip.git, version 2.1.2 released) as the Internet support.
  2. Set LWIP_IPV6 macro to 0
  3. Compile the redis and run redis-server
  4. We can observe that redis cannot create any http server.

Expected behavior

The socket should be set to -1 to avoid double close.

Additional information

It can simply resolved by adding "s = -1" in the conditional branch at line 504.