It seem the 'ctx->sock = sock' assignment on line 644 of apn.c should move up to line 607 (before #ifdef _WIN32).
Right now fcntl/ioctlsocket is called on a -1. (condition of ctx->sock is checked earlier).
Also, in case a connection is never established, ( ! connected ), the socket is never closed as the 'ctx -> sock = sock' assignment will not be performed until past the 'if'statement.
It seem the 'ctx->sock = sock' assignment on line 644 of apn.c should move up to line 607 (before #ifdef _WIN32). Right now fcntl/ioctlsocket is called on a -1. (condition of ctx->sock is checked earlier). Also, in case a connection is never established, ( ! connected ), the socket is never closed as the 'ctx -> sock = sock' assignment will not be performed until past the 'if'statement.