underlying WinSock SOCKET. Therefore, if we plan to modify the
SOCKET in a socket, we must remove it from the tree before doing so,
and put it back again afterwards. Otherwise it'll violate the tree's
sorting order, and sooner or later someone will try to find it and
get back NULL.
git-svn-id: svn://svn.tartarus.org/sgt/putty@7795
cda61777-01e9-0310-a592-
d414129be87e
return -1;
if (as > bs)
return +1;
+ if (a < b)
+ return -1;
+ if (a > b)
+ return +1;
return 0;
}
family = AF_INET;
}
+ /*
+ * Remove the socket from the tree before we overwrite its
+ * internal socket id, because that forms part of the tree's
+ * sorting criterion. We'll add it back before exiting this
+ * function, whether we changed anything or not.
+ */
+ del234(sktree, sock);
+
s = p_socket(family, SOCK_STREAM, 0);
sock->s = s;
sock->writable = 1;
}
- add234(sktree, sock);
-
err = 0;
ret:
+
+ /*
+ * No matter what happened, put the socket back in the tree.
+ */
+ add234(sktree, sock);
+
if (err)
plug_log(sock->plug, 1, sock->addr, sock->port, sock->error, err);
return err;