Null check before dereference

Fix Coverity error CID 56880

Signed-off-by: Gregor Jasny <gjasny@googlemail.com>
Fix integer shift overflow if both tcp_socket and udp_socket are set

The problem occurs if at the start of the loop the sockindex is at the
last valid ARES_GETSOCK_MAXNUM position. If then both udp_socket and
tcp_socket are valid, sockindex gets incremented for UDP first and
points one entry behind the array for the tcp block.
So the fix is to check after every increment of sockindex if it is still
valid.

Fix Coverity error CID 56878

Signed-off-by: Gregor Jasny <gjasny@googlemail.com>
Free temporary variable in error path

Fix Coverity CID 56890

Signed-off-by: Gregor Jasny <gjasny@googlemail.com>
Re-start loop if select fails

Fix Coverity error CID 56882

Signed-off-by: Gregor Jasny <gjasny@googlemail.com>
Prevent tmpbuf from overrunning

Fix Coverity error CID 56886.

Signed-off-by: Gregor Jasny <gjasny@googlemail.com>