socket file descriptor leak
Brought to you by:
lhanson
The makeSocket() function contains a file descriptor leak. I believe it happens if the socket() call succeeds but the connect() fails. In this case, the socket descriptor returned from socket() should be closed before returning.
I noticed this problem because on my system the network was unreachable for a few seconds every 10 minutes. After running my program for a 4 hours, the process hit the open file descriptor limit (1024 open descriptors) and could not make any further HTTP requests.
A possible fix is inserting the close() call like so:
ret = connect(sock, (struct sockaddr *)&sa, sizeof(sa));
if(ret == -1) { close(sock); errorSource = ERRNO; return -1; }