The following was tripped over while working on Bug 695420. debugbin/gswin32c -Z@$? -q -sDEVICE=pdfwrite -o x.pdf -dLastPage=1 -c "<< /ProcessColorModel /DeviceGray >> setpagedevice" -f examples/annots.pdf dies with: Error: /rangecheck in .installpagedevice <--- SNIP ---> GPL Ghostscript GIT PRERELEASE 9.15: Unrecoverable error, exit code 1 GPL Ghostscript GIT PRERELEASE 9.15: .\psi\ilocate.c(597): Reference to free object 0x2190a10(168), in chunk 0x2189b08! while validating chunk 0x218a2e8 (0x21c9fa0..0x21d0e90, 0x21d0e90..0x21d0e90..0x21d0e90) GPL Ghostscript GIT PRERELEASE 9.15: .\psi\ilocate.c(258): while validating memory 0x226f980, space 8, level -1
I'd have to guess this is a similar problem to the last one (Bug #695420), something is awry in the page device dictionary or some similar saved resoruce, after it has been altered by pdfwrite in some way. You can drop the -q and -Z@$? parameters. The error seems to occur during end of job restore. FWIW I never get the reference to freed memory, even with the memory checking enabled, just a rangecheck error.
commit 55bd0a59caf26a59f852e2dec5b76ad399d9408b fixes the rangecheck error and also the memory warning for me. Ray I'd be grateful if you would check that it solves the memory problem for you as well, I'm not completely convinced that it should have. That commit also addresses the problem of OutputICCProfile not being sent to the device for me. Details of the problem and the fix can be found in the commit log
I confirmed that th patch makes both the rangecheck AND the ilocate problem go away for me, and no segfault with the release build.