[gs-commits] rev 11785 - in trunk/gs: base psi

mvrhel at ghostscript.com mvrhel at ghostscript.com
Tue Oct 12 05:52:17 UTC 2010


Author: mvrhel
Date: 2010-10-12 05:52:16 +0000 (Tue, 12 Oct 2010)
New Revision: 11785

Modified:
   trunk/gs/base/gxpcmap.c
   trunk/gs/psi/zpcolor.c
Log:
Fix for a large memory leak that can occur when a pattern cache entry is freed and a transparency buffer exists in the entry.  A problem was that the pdf14 device, which contains pointers to the buffer, had its close device procedure set to forward due to the device being set in a disabled state during pattern_paint_finish.  The close device proc for the pdf14 device contains the calls to actually free the buffers so this was not occurring (instead we were forwarding to another device).  In addition, the pdf14 device itself was not being destroyed.  With this commit, when the pattern entry is freed, the  pdf14 device is now closed, which frees the buffers, and the pdf14 device is properly reference count decremented to result in the device itself getting freed.  Regression run revealed no problems.

Modified: trunk/gs/base/gxpcmap.c
===================================================================
--- trunk/gs/base/gxpcmap.c	2010-10-11 17:07:18 UTC (rev 11784)
+++ trunk/gs/base/gxpcmap.c	2010-10-12 05:52:16 UTC (rev 11785)
@@ -693,6 +693,8 @@
 static void
 gx_pattern_cache_free_entry(gx_pattern_cache * pcache, gx_color_tile * ctile)
 {
+    gx_device *temp_device;
+
     if ((ctile->id != gx_no_bitmap_id) && !ctile->is_dummy) {
 	gs_memory_t *mem = pcache->memory;
 	gx_device_memory *pmdev;
@@ -747,7 +749,10 @@
                 ctile->ttrans->transbytes = NULL;
             } else {
 	        dev_proc(ctile->ttrans->pdev14, close_device)((gx_device *)ctile->ttrans->pdev14);
-                ctile->ttrans->pdev14 = NULL;  /* should be ok due to pdf14_close */
+                temp_device = ctile->ttrans->pdev14;
+                gx_device_retain(temp_device, false);
+                rc_decrement(temp_device,"gx_pattern_cache_free_entry");
+                ctile->ttrans->pdev14 = NULL;  
                 ctile->ttrans->transbytes = NULL;  /* should be ok due to pdf14_close */
                 ctile->ttrans->fill_trans_buffer = NULL; /* This is always freed */
             }

Modified: trunk/gs/psi/zpcolor.c
===================================================================
--- trunk/gs/psi/zpcolor.c	2010-10-11 17:07:18 UTC (rev 11784)
+++ trunk/gs/psi/zpcolor.c	2010-10-12 05:52:16 UTC (rev 11785)
@@ -297,27 +297,18 @@
 	(gs_pattern1_instance_t *)gs_currentcolor(igs->saved)->pattern;
     gx_device_pattern_accum const *padev = (const gx_device_pattern_accum *) pdev;
 
-
     if (pdev != NULL) {
 	gx_color_tile *ctile;
 	int code;
-
 	if (pinst->template.uses_transparency) {
 	    gs_state *pgs = igs;
 	    int code;
-
             /* Get PDF14 buffer information */
-
             code = pdf14_get_buffer_information(pgs->device,padev->transbuff);
+            /* PDF14 device (and buffer) is destroyed when pattern cache 
+               entry is removed */
 	    if (code < 0)
 		return code;
-
-            /* Do not pop the device.  Instead go ahead and and disable it.
-               We will later free it when the pattern cache entry is freed. 
-               The ctile maintains a pointer to the device */
-
-            pdf14_disable_device(pgs->device);
-
 	} 
 	code = gx_pattern_cache_add_entry((gs_imager_state *)igs, pdev, &ctile);
 	if (code < 0)



More information about the gs-commits mailing list