Skip to content
Tcl Source Code View Ticket
Login

View Ticket

2026-11-11
14:10 • Ticket [d402ffe76f] Win32 potential crash when using main() status still Clo... artifact: cd4075d4e3 user: jan.nijtmans
13:56 • Closed ticket [d402ffe76f]. artifact: 7a12b7ef81 user: jan.nijtmans
13:50
Follow-up to [d402ffe76f]: Win32 potential crash when using main() check-in: 41c90339a6 user: jan.nijtmans tags: core-8-6-branch
09:00
Follow-up to [d402ffe76f]: Win32 potential crash when using main() check-in: 7cbf49bdb5 user: jan.nijtmans tags: core-9-0-branch
2026-11-10
20:02 • Ticket [d402ffe76f] Win32 potential crash when using main() status still Ope... artifact: 23a9e91ee1 user: jan.nijtmans
20:00
Follow-up to [d402ffe76f]: Win32 potential crash when using main() check-in: 6019bf7e07 user: jan.nijtmans tags: trunk, main
19:27 • Open ticket [d402ffe76f]: Win32 potential crash when using main() plus 3 oth... artifact: e3a1b985c9 user: oehhar
18:10 • Ticket [d402ffe76f]: 6 changes artifact: 11c618ba05 user: anonymous
2020-12-30
01:45 • New ticket [e7eb94e8d1] ambiguous hashes, typo in changes. artifact: 3f7b024dd1 user: chrstphrchvz
2020-05-12
11:29 • Closed ticket [d402ffe76f]: Win32 potential crash when using main() plus 6 o... artifact: 135b0ca767 user: jan.nijtmans
2020-05-11
10:41
Fix [d402ffe76]: Win32 potential crash when using main(). Thanks to Christian Werner for the Bug rep... check-in: 778543bca7 user: jan.nijtmans tags: core-8-6-branch
2020-05-10
20:58 • Ticket [d402ffe76f] Win32 potential crash when using main() status still Ope... artifact: a024f310b9 user: jan.nijtmans
20:13 • New ticket [d402ffe76f]. artifact: e2eaec4a73 user: chw

Win32 potential crash when using main()

Closed / Fixedd402ffe76f90c650bcf18d5b5c58a0b77770ed48Created 7 years agoUpdated 21 days ago
Descriptionplain2020-05-10 20:13:51
According to MSDN the _wenviron variable initially is NULL when
the program starts via main() but is populated on the very first
call of _wgetenv() or _wputenv().

The current core-8-6-branch requires in TclSetupEnv() _wenviron
to be non NULL, otherwise a crash (access violation, segfault)
happens. When some custom code embeds Tcl as a library and uses
main() instead of wmain() as its program entry point, that crash
is most likely.

Please see https://www.androwish.org/home/info/93ee54fe8cd2e176
for a possible solution.
Referenced by4
jan.nijtmanswiki2020-05-10 20:58:59

Thanks! I will have a look at this.

jan.nijtmanswiki2020-05-12 11:29:13

Merged to core-8-6-branch and up. Thanks for the report and the fix!

anonymous (claiming to be [email protected])plain2026-11-10 18:10:43
This issue still exists in 9.0 due to TclFinalizeIOSubsystem() calling TclGetEnv() around line 598 of tclIO.c.

It's possible for trivial apps to initialise and finalise and hit this path. I encountered this creating a minimal repro for a build issue with CPython. 

The fix I'd suggest is to have TclpFindVariable (in tclWinInit.c) check for a NULL _wenviron and do an arbitrary _wgetenv to initialise before continuing. I assume there's some reason for doing your own search rather than using _wgetenv (or _wgetenv_s), but if not, switching to that for the search ought to be fine too.
oehhar Open ticket [d402ffe76f]. [History diff]2026-11-10 19:27:25
jan.nijtmanswiki2026-11-10 20:02:21

Something like [this]?

jan.nijtmanswiki2026-11-11 13:56:12

No merged to [trunk], core-9-0-branch and core-8-6-branch

jan.nijtmanswiki2026-11-11 14:10:58

Now merged to [trunk], core-9-0-branch and core-8-6-branch

Log in (anonymous is fine) to add a comment.