simon-git: putty (main): Simon Tatham
Commits to Tartarus hosted VCS
tartarus-commits at lists.tartarus.org
Thu Jul 31 13:00:10 BST 2025
TL;DR:
3cbe8522 Windows: fix memory leak in the stale-netevent fix.
2eee8848 Windows: fix stale-netevent problem in the CLI tools.
Repository: https://git.tartarus.org/simon/putty.git
On the web: https://git.tartarus.org/?p=simon/putty.git
Branch updated: main
Committer: Simon Tatham <anakin at pobox.com>
Date: 2025-07-31 13:00:10
commit 3cbe8522a0339d39eaad212d050c4930b23cc767
web diff https://git.tartarus.org/?p=simon/putty.git;a=commitdiff;h=3cbe8522a0339d39eaad212d050c4930b23cc767;hp=bb8894ff12f9175d8ebc2c0efe2b56a72f091878
Author: Simon Tatham <anakin at pobox.com>
Date: Thu Jul 31 12:51:37 2025 +0100
Windows: fix memory leak in the stale-netevent fix.
When we delete toplevel callbacks for a defunct socket, we must also
free the tiny parameter structure we allocated for each one.
windows/select-gui.c | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)
commit 2eee88480aedaa85079c86179743237c74643492
web diff https://git.tartarus.org/?p=simon/putty.git;a=commitdiff;h=2eee88480aedaa85079c86179743237c74643492;hp=3cbe8522a0339d39eaad212d050c4930b23cc767
Author: Simon Tatham <anakin at pobox.com>
Date: Thu Jul 31 12:49:23 2025 +0100
Windows: fix stale-netevent problem in the CLI tools.
This fixes in the CLI tools â Plink and friends â the same bug fixed
by the recent commit bb8894ff12f9175: if an HTTP proxy demands
authentication via a 407 response with Connection: close, then PuTTY
immediately makes a second connection to the proxy, which (often)
reuses the same socket id at the Win32 API layer, and then a lingering
activity notification for the previous socket confuses the handling of
the new one.
My entire diagnosis and fix in the previous commit were completely
derived from reasoning about window message queues and WSAAsyncSelect,
so I jumped to the conclusion that the problem would be specific to
the GUI tools, which are the ones that _use_ WSAAsyncSelect. But I
didn't actually test with Plink. When I did, it turns out that for a
completely different reason, cliloop.c has an isomorphic bug, causing
the same symptom by a different route.
In the CLI tools, instead of WSAAsyncSelect, we use WSAEventSelect, in
which Windows signals an event object when socket activity happens. We
respond by calling WSAEnumNetworkEvents, which tells us what kind of
activity it was, as a bitmap of FD_READ, FD_WRITE, FD_CLOSE etc. Then
we iterate over those bits in a particular order, processing each one
with a call to select_result().
In this case, the problem wasn't anything lingering in a _queue_. It
was simply that we call select_result() to process an FD_READ
notification for the socket, which closes the socket and makes a new
one, and then select_result() returns to the for-loop which is still
iterating over the bit mask returned from WSAEnumNetworkEvents, so in
the next loop iteration it tries to process the FD_CLOSE notification
for the old socket, not realising that the socket went away in the
meantime.
I've fixed this by the brute-force technique of moving all the
select_result calls out of the for-loop completely. Now cliloop.c does
the same thing as select-gui.c: it schedules each instance of handling
socket activity as a toplevel callback, and the callbacks don't
actually _happen_ until we've completely finished handling the
signalled event object. So now, when we're handling FD_READ and still
have FD_CLOSE left in a queue somewhere, the queue is the toplevel
callback system instead of a for-loop further up the call stack â and
that means we can clear the queue via delete_callbacks() in the same
way that the previous commit did it for the GUI tools.
# This is the commit message #2:
# fixup! Windows: fix stale-netevent problem in the CLI tools.
windows/cliloop.c | 47 ++++++++++++++++++++++++++++++++++++++++++-----
windows/select-cli.c | 4 ----
2 files changed, 42 insertions(+), 9 deletions(-)
More information about the tartarus-commits
mailing list