The Windows utf8 version of Ghostscript crashes when one or the other of the GS_* environment variables are not set. Since GS_OPTIONS is rarely set and it is fetched at startup, this means GS usually won't run. The reason is the utf8 "gp_getenv_registry()" fails to return the "entry not found" verdict, instead is returns "buffer too small", sets the needed buffer size to zero and leaves the buffer for the output value undefined. The code calls "gp_getenv_registry()" once with buffer size = 0 in order to know how big the buffer needs to be, and if the entry exists calls the function a 2nd time to get the value assuming this 2nd call cannot fail. Because the 2nd call also has buffer size = 0, no value is returned. That function also has other problems, like doing "free(NULL)". I also hope the patch suggested in comment #1 makes the flow-control in the code more clear.
Created attachment 7679 [details] Suggested patch. Bug #692348: utf8-Ghostscript - Crash if any of the GS_ environment variables not defined. For GS_ registry entries that are not set, the utf8 version of 'gp_getenv_registry()' incorrectly returned an 'insufficient buffer space' verdict and let the 'needed buffer size' to 0 (cbData = 0 after 'RegQueryValueExW()'). The call to fetch the value was then made also with a 0-sized buffer, did the same thing, and left the buffer for the value undefined. There were also other problems, for example non-REG_SZ entries were ignored only when the value was actually requested (not during the request for the buffer size) and the function was doing 'free(wp)' with wp == NULL in a few cases.
This patch has been committed by Ray on 2011-07-17 as a rev. 44a2fd0bb1e2dd12e9ba475da0bdbb93081325d5