Browse Source

* Cleanup some socket kills

Bryan Drewery 16 years ago
parent
commit
c4bf758e57
5 changed files with 22 additions and 9 deletions
  1. 8 3
      src/botnet.c
  2. 6 2
      src/mod/server.mod/server.c
  3. 3 2
      src/mod/share.mod/share.c
  4. 4 2
      src/mod/update.mod/update.c
  5. 1 0
      src/net.c

+ 8 - 3
src/botnet.c

@@ -1099,9 +1099,12 @@ static void botlink_real(int i)
 //  if (dcc[i].sock > 0)
 //    identd_open();                      /* will be closed when an ident is replied. */
 
-  if (dcc[i].sock < 0 || open_telnet_raw(dcc[i].sock, dcc[i].host, dcc[i].port, 0, 1) < 0)
+  int open_telnet_return;
+  if (dcc[i].sock < 0 || (open_telnet_return = open_telnet_raw(dcc[i].sock, dcc[i].host, dcc[i].port, 0, 1)) < 0) {
+    if (open_telnet_return == -1)
+      dcc[i].sock = -1;
     failed_link(i);
-  else { /* let's attempt to initiate SSL before ANYTHING else... */
+  } else { /* let's attempt to initiate SSL before ANYTHING else... */
     dcc[i].ssl = 0;
   }
 
@@ -1270,8 +1273,10 @@ static void tandem_relay_dns_callback(int id, void *client_data, const char *hos
   dcc[i].u.relay->chat->current_lines = 0;
   dcc[i].timeval = now;
 
-  if (open_telnet_raw(dcc[i].sock, bd::String(ips[0]).c_str(), dcc[i].port, 0) < 0)
+  if (open_telnet_raw(dcc[i].sock, bd::String(ips[0]).c_str(), dcc[i].port, 0) < 0) {
+    dcc[i].sock = -1;
     failed_tandem_relay(i);
+  }
 }
 
 /* Input from user before connect is ready

+ 6 - 2
src/mod/server.mod/server.c

@@ -945,11 +945,15 @@ static void dcc_chat_hostresolved(int i)
 #else
   dcc[i].sock = getsock(0);
 #endif /* USE_IPV6 */
-  if (dcc[i].sock < 0 || open_telnet_dcc(dcc[i].sock, ip, buf) < 0) {
+  int open_telnet_return;
+  if (dcc[i].sock < 0 || (open_telnet_return = open_telnet_dcc(dcc[i].sock, ip, buf)) < 0) {
+    if (open_telnet_return == -1)
+      dcc[i].sock = -1;
     strlcpy(buf, strerror(errno), sizeof(buf));
     putlog(LOG_MISC, "*", "%s: CHAT (%s!%s)", "DCC connection failed", dcc[i].nick, dcc[i].host);
     putlog(LOG_MISC, "*", "    (%s)", buf);
-    killsock(dcc[i].sock);
+    if (dcc[i].sock != -1)
+      killsock(dcc[i].sock);
     lostdcc(i);
   } else {
     bool ok = 1;

+ 3 - 2
src/mod/share.mod/share.c

@@ -998,9 +998,10 @@ share_ufsend(int idx, char *par)
 #else
     sock = getsock(SOCK_BINARY);        /* Don't buffer this -> mark binary. */
 #endif /* USE_IPV6 */
-    if (sock < 0 || open_telnet_dcc(sock, ip, port) < 0) {
+    int open_telnet_return;
+    if (sock < 0 || (open_telnet_return = open_telnet_dcc(sock, ip, port)) < 0) {
       fclose(f);
-      if (sock != -1)
+      if (open_telnet_return != -1 && sock != -1)
         killsock(sock);
       putlog(LOG_BOTS, "@", "Asynchronous connection failed!");
       dprintf(idx, "s e Can't connect to you!\n");

+ 4 - 2
src/mod/update.mod/update.c

@@ -132,8 +132,10 @@ static void update_ufsend(int idx, char *par)
 #else
     sock = getsock(SOCK_BINARY); /* Don't buffer this -> mark binary. */
 #endif /* USE_IPV6 */
-    if (sock < 0 || open_telnet_dcc(sock, ip, port) < 0) {
-      killsock(sock);
+    int open_telnet_return;
+    if (sock < 0 || (open_telnet_return = open_telnet_dcc(sock, ip, port)) < 0) {
+      if (open_telnet_return != -1 && sock != -1)
+        killsock(sock);
       putlog(LOG_BOTS, "*", "Asynchronous connection failed!");
       dprintf(idx, "sb e Can't connect to you!\n");
       zapfbot(idx);

+ 1 - 0
src/net.c

@@ -583,6 +583,7 @@ int open_telnet_raw(int sock, const char *ipIn, port_t sport, bool proxy_on, int
       initialize_sockaddr(is_resolved, ip, port, &so);
     } else {	/* if not resolved, resolve it with blocking calls.. (shouldn't happen ever) */
       sdprintf("WARNING: open_telnet_raw(%s,%d) was passed an unresolved hostname.", ip, port);
+      killsock(sock);
       return -1;
     }
     socklen = SIZEOF_SOCKADDR(so);