Sophie

Sophie

distrib > Mageia > 6 > armv7hl > media > core-updates-src > by-pkgid > bc219369320b6b5781eed48254462cef > files > 28

ghostscript-9.25-1.2.mga6.src.rpm

From bf9f3f1536487b4d67643ac3d8bddd149a2b3fa0 Mon Sep 17 00:00:00 2001
From: Chris Liddell <chris.liddell@artifex.com>
Date: Wed, 10 Oct 2018 16:24:38 +0100
Subject: [PATCH] Close a device before any other 'finalize' actions

Previously, when a device object was being finalized, we were calling the
device's own finalize method, and (possibly) freeing the reference counted
icc data before calling gs_closedevice() to ensure the device is genuinely
closed.

Reorder the operations so closing the device is the *first* thing we do.
---
 base/gdevsclass.c | 4 ++--
 base/gsdevice.c   | 8 +++++---
 2 files changed, 7 insertions(+), 5 deletions(-)

diff --git a/base/gdevsclass.c b/base/gdevsclass.c
index 8b2642e..f02ea4a 100644
--- a/base/gdevsclass.c
+++ b/base/gdevsclass.c
@@ -901,11 +901,11 @@ void default_subclass_finalize(const gs_memory_t *cmem, void *vptr)
     generic_subclass_data *psubclass_data = (generic_subclass_data *)dev->subclass_data;
     (void)cmem; /* unused */
 
+    discard(gs_closedevice(dev));
+
     if (dev->finalize)
         dev->finalize(dev);
 
-    discard(gs_closedevice(dev));
-
     if (psubclass_data) {
         gs_free_object(dev->memory->non_gc_memory, psubclass_data, "gx_epo_finalize(suclass data)");
         dev->subclass_data = NULL;
diff --git a/base/gsdevice.c b/base/gsdevice.c
index a99ff25..e0cf105 100644
--- a/base/gsdevice.c
+++ b/base/gsdevice.c
@@ -51,11 +51,11 @@ gx_device_finalize(const gs_memory_t *cmem, void *vptr)
     gx_device * const dev = (gx_device *)vptr;
     (void)cmem; /* unused */
 
+    discard(gs_closedevice(dev));
+
     if (dev->icc_struct != NULL) {
         rc_decrement(dev->icc_struct, "gx_device_finalize(icc_profile)");
     }
-    if (dev->finalize)
-        dev->finalize(dev);
 
     /* Deal with subclassed devices. Ordinarily these should not be a problem, we
      * will never see them, but if ths is a end of job restore we can end up
@@ -71,7 +71,9 @@ gx_device_finalize(const gs_memory_t *cmem, void *vptr)
         dev->PageList = 0;
     }
 
-    discard(gs_closedevice(dev));
+    if (dev->finalize)
+        dev->finalize(dev);
+
     if (dev->stype_is_dynamic)
         gs_free_const_object(dev->memory->non_gc_memory, dev->stype,
                              "gx_device_finalize");
-- 
2.9.1