Skip to content
Tcl Source Code Ticket Change Details
Login

Ticket Change Details

Overview

Artifact ID: 8a06d0213313115532834ca0ed22574c4ba9a2bd7fb556610e17b4fd9065d68c
Ticket: 06f19cc401de076eea76538424796d1ee54ed221
socket_*-12.3 crashes on Windows 11
User & Date: apnadkarni on 2026-05-28 06:40:09
Changes

  1. icomment:
    Managed to reliably reproduce by running the tests continuously. Fails within 30 iterations due to use after free. The bug is present in release builds as well but shows up more easily in debug builds because the C ucrt/msvcrt runtimes scrub memory only in debug builds.
    
    Proposed fix is in the bug-06f19cc4-with-tcltest branch. 
    
    Diagnosis: The socket implementation of Windows maintains a separate "socket thread" for a Tcl thread to handle socket I/O. The list of live sockets is maintained in a TSD list within the Tcl thread and also shared with the socket thread. When a channel is in normal operation, the socket state structure is removed from this list via the socket channel implementation's ThreadActionProc (via a CutChannel call). However, when a thread exits, TclFinalizeIOSubsystem frees the socket state structure without calling CutChannel. The socket thread still has access to it via the shared list and depending on when the socket closure windows message is received, accesses the freed memory.
    
    The fix simply adds a CutChannel to TclFinalizeIOSubsystem prior to the ChanClose. I believe this should apply to all platforms but I'm not sure of the Unix implementations so it's ifdef'ed to WIN32.
    
    Although a one-liner, it's also a fairly low level change that needs substantial airtime for an issue that only arises on thread exits with open sockets so do not think it should be backported to 9.0.4.
    
    Reviews welcomed.
    
  2. login: "apnadkarni"
  3. mimetype: "text/x-markdown"