summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Liddell <chris.liddell@artifex.com>2018-08-23 15:41:18 +0100
committerChris Liddell <chris.liddell@artifex.com>2018-08-23 17:07:20 +0100
commit241d91112771a6104de10b3948c3f350d6690c1d (patch)
treee5f19756ff41ec46d815ca341baec8c6e7bb11bc
parentc432131c3fdb2143e148e8ba88555f7f7a63b25e (diff)
Bug 699664: Ensure the correct is in place before cleanup
If the PS job replaces the device and leaves that graphics state in place, we wouldn't cleanup the default device in the normal way, but rely on the garbage collector. This works (but isn't ideal), *except* when the job replaces the device with the null device (using the nulldevice operator) - this means that .uninstallpagedevice doesn't replace the existing device with the nulldevice (since it is already installed), the device from the graphics ends up being freed - and as it is the nulldevice, which we rely on, memory corruption and a segfault can happen. We avoid this by checking if the current device is the nulldevice, and if so, restoring it away, before continuing with the device cleanup.
-rw-r--r--psi/imain.c10
1 files changed, 10 insertions, 0 deletions
diff --git a/psi/imain.c b/psi/imain.c
index 2fe15465e..138bfc82b 100644
--- a/psi/imain.c
+++ b/psi/imain.c
@@ -936,6 +936,16 @@ gs_main_finit(gs_main_instance * minst, int exit_status, int code)
936 i_ctx_p = minst->i_ctx_p; /* interp_reclaim could change it. */ 936 i_ctx_p = minst->i_ctx_p; /* interp_reclaim could change it. */
937 } 937 }
938 938
939 if (i_ctx_p->pgs != NULL && i_ctx_p->pgs->device != NULL &&
940 gx_device_is_null(i_ctx_p->pgs->device)) {
941 /* if the job replaced the device with the nulldevice, we we need to grestore
942 away that device, so the block below can properly dispense
943 with the default device.
944 */
945 int code = gs_grestoreall(i_ctx_p->pgs);
946 if (code < 0) return_error(gs_error_Fatal);
947 }
948
939 if (i_ctx_p->pgs != NULL && i_ctx_p->pgs->device != NULL) { 949 if (i_ctx_p->pgs != NULL && i_ctx_p->pgs->device != NULL) {
940 gx_device *pdev = i_ctx_p->pgs->device; 950 gx_device *pdev = i_ctx_p->pgs->device;
941 const char * dname = pdev->dname; 951 const char * dname = pdev->dname;