diff --git a/netio.c b/netio.c
index 42d1b32d23113904ca617ae0444ff4e92a9a6594..9c84958a5465d8397106edd90ee7ad12270a2ce7 100644
--- a/netio.c
+++ b/netio.c
@@ -169,11 +169,10 @@ struct dropbear_progress_connection *connect_remote(const char* remotehost, cons
 		snprintf(c->errstring, len, "Error resolving '%s' port '%s'. %s", 
 				remotehost, remoteport, gai_strerror(err));
 		TRACE(("Error resolving: %s", gai_strerror(err)))
-		return NULL;
+	} else {
+		c->res_iter = c->res;
 	}
 
-	c->res_iter = c->res;
-
 	return c;
 }
 
@@ -220,7 +219,7 @@ void handle_connect_fds(fd_set *writefd) {
 		socklen_t vallen = sizeof(val);
 		struct dropbear_progress_connection *c = iter->item;
 
-		if (!FD_ISSET(c->sock, writefd)) {
+		if (c->sock < 0 || !FD_ISSET(c->sock, writefd)) {
 			continue;
 		}