Closed dgelessus closed 3 years ago
Thanks. This was a quite serious bug that shows mostly on MacOS, but could harm any non-Windows system and indeed occasionally also affects Linux. Fixed with e2c203a591072dc78bb9452f84d4187c1c48b864 and d83ed3ef92aafb59387225ac8c4a106195cb4979.
First fixes the crash. Second loosing part of the environment and provides a cleaner fix for the crash.
Thank you for the quick fix! All seems to work correctly now on my machine.
This is on macOS 10.14.6, with SWI-Prolog built from source (swi-prolog/swipl-devel@2a16e87857605f59645ace4d578e9791fb5dbe92, swi-prolog/packages-clib@50b35f579d07e14e1b5833b0032bc60d75c41a10).
The
environment(Env)
option ofprocess:process_create/3
doesn't work correctly. According to the docs,environment(Env)
should pass the environment of the current process on to the called process, while replacing/adding the variables listed inEnv
. Actually, it seems that although all variables fromEnv
are correctly passed to the new process, most of the variables from the current process are dropped and only a small random selection is kept:Also, passing an empty
Env
(i. e.environment([])
) causes a segmentation fault.Stack trace
```prolog ?- process_create('/usr/bin/printenv', [], [environment([])]). SWI-Prolog [thread 1 (main) at Wed Dec 2 20:54:49 2020]: received fatal signal 11 (segv) C-stack trace labeled "crash": [0]The segfault seems to be because the helper function
already_in_env
in process.c doesn't handleenv
beingNULL
. This happens when an empty environment list was passed, because then the buffer in which the environment is constructed never has any variables added to it, so it is stillNULL
by the time thatalready_in_env
is called on it.I haven't figured out though what's causing most of the existing environment variables to be "lost" when a non-empty list is passed.