From zvika.meiseles at gmail.com Tue May 5 13:18:11 2026 From: zvika.meiseles at gmail.com (Zvika Meiseles) Date: Tue, 5 May 2026 20:18:11 +0300 Subject: unbalanced WSAStartup/WSACleanup calls Message-ID: Hi, I suspect the krb5 code may execute unbalanced WSAStartup/WSACleanup calls, causing premature WinSock cleanup and application crash (following a crash I'm investigating where krb5 context cleanup causes WinSock destruction). I wanted to run this by the group before submitting a bug report, just to make sure I'm not imagining things. The code in question is in src\lib\krb5\os\init_os_ctx.c and src\lib\krb5\krb\init_ctx.c : When a context is created, after it is successfully allocated in krb5_init_context_profile, k5_os_init_context is called, which in turn may call WSAStartup, and that call may also fail. However, from this point forward, any failure will cause a jump to :cleanup and a call to krb5_free_context. It will, in turn, call WSACleanup since ctx is not null (it is only nullified in the success path). I think we need to add a flag tracking whether WSAStartup was (successfully) called, and only then call WSACleanup. WDYT? Zvika From ghudson at mit.edu Tue May 5 20:45:29 2026 From: ghudson at mit.edu (Greg Hudson) Date: Tue, 5 May 2026 20:45:29 -0400 Subject: unbalanced WSAStartup/WSACleanup calls In-Reply-To: References: Message-ID: <82772a20-8cf6-453f-96b6-ef1d399d15ce@mit.edu> On 5/5/26 13:18, Zvika Meiseles wrote: > I suspect the krb5 code may execute unbalanced WSAStartup/WSACleanup calls, > causing premature WinSock cleanup and application crash (following a crash > I'm investigating where krb5 context cleanup causes WinSock destruction). I think your analysis is correct. A failure opening or parsing the config file (via os_init_paths()) will result in a call to WSACleanup() with no corresponding call to WSAStartup().