[gs-cvs] rev 8803 - trunk/gs/src
leonardo at ghostscript.com
leonardo at ghostscript.com
Tue Jun 24 07:16:31 PDT 2008
Author: leonardo
Date: 2008-06-24 07:16:29 -0700 (Tue, 24 Jun 2008)
New Revision: 8803
Modified:
trunk/gs/src/devs.mak
trunk/gs/src/gdevbbox.c
trunk/gs/src/gdevpdfi.c
trunk/gs/src/gdevplnx.c
trunk/gs/src/gdevpx.c
trunk/gs/src/gdevtrac.c
trunk/gs/src/gdevvec.c
trunk/gs/src/gdevvec.h
trunk/gs/src/gsimage.h
trunk/gs/src/gxclimag.c
trunk/gs/src/gxidata.c
trunk/gs/src/gximag3x.c
trunk/gs/src/gximage.h
trunk/gs/src/gximage1.c
trunk/gs/src/gximage3.c
trunk/gs/src/gxiparam.h
trunk/gs/src/lib.mak
Log:
Fix (graphics) : Clean image enumerator before releasing it.
DETAILS :
Bug 688845 "Segmentation Fault on EPS 2 PDF conversion", comment #38.
Adobe Illustrator creates a Postscript document,
in which an image data procedure executes 'save',
and the corresponding 'restore' appears after the image end.
DCue to that the image enumerator is freed at a higher save level than
it was allocated, so that gs_free_object works idle.
Nevertheless pointers must not in the structure,
because they may point to blocks already released
by the client's subclass method for end_image.
Leaving them uncleaned caused a real crash in the garbager - see bug 688845.
The patch defines the new function gs_image_free_enum,
which is intendend for a safe releasing of an image enumerator
from Postscript interpreter.
It cleans the entire subclassed enumerator,
including all possible pointers created by subclasses.
All end_image implementations,
which may be called from Postscript interpreter,
must call this function for releasing image enumerators.
The 'memory' pointer moved from subclasses to gx_image_enum_common.
We believe that in the old code all subclasses define and initialize it.
Working on this patch we suspected memory leaks
from image enumerators with some devices.
Particularly we suspect that subclasses if gx_device_vector
(pdfwrite, ps2write, etc.) never release image enumerators (not sure).
This patch does not do any attempt to re[pair such leaks,
because we want the new code doesn't
change the behavour too much in order to simplify the testing.
A work on leaks to be done separately.
EXPECTED DIFFERENCES :
None.
Modified: trunk/gs/src/devs.mak
===================================================================
--- trunk/gs/src/devs.mak 2008-06-22 09:47:49 UTC (rev 8802)
+++ trunk/gs/src/devs.mak 2008-06-24 14:16:29 UTC (rev 8803)
@@ -1090,7 +1090,7 @@
$(GLOBJ)gdevpx.$(OBJ) : $(GLSRC)gdevpx.c\
$(math__h) $(memory__h) $(string__h)\
- $(gx_h) $(gsccolor_h) $(gsdcolor_h) $(gserrors_h)\
+ $(gx_h) $(gsccolor_h) $(gsdcolor_h) $(gxiparam_h) $(gserrors_h)\
$(gxcspace_h) $(gxdevice_h) $(gxpath_h)\
$(gdevpxat_h) $(gdevpxen_h) $(gdevpxop_h) $(gdevpxut_h) $(gdevvec_h)\
$(srlx_h) $(strimpl_h)
Modified: trunk/gs/src/gdevbbox.c
===================================================================
--- trunk/gs/src/gdevbbox.c 2008-06-22 09:47:49 UTC (rev 8802)
+++ trunk/gs/src/gdevbbox.c 2008-06-24 14:16:29 UTC (rev 8803)
@@ -917,7 +917,6 @@
typedef struct bbox_image_enum_s {
gx_image_enum_common;
- gs_memory_t *memory;
gs_matrix matrix; /* map from image space to device space */
const gx_clip_path *pcpath;
gx_image_enum_common_t *target_info;
@@ -1115,7 +1114,7 @@
bbox_image_enum *pbe = (bbox_image_enum *) info;
int code = gx_image_end(pbe->target_info, draw_last);
- gs_free_object(pbe->memory, pbe, "bbox_end_image");
+ gx_image_free_enum(&info);
return code;
}
Modified: trunk/gs/src/gdevpdfi.c
===================================================================
--- trunk/gs/src/gdevpdfi.c 2008-06-22 09:47:49 UTC (rev 8802)
+++ trunk/gs/src/gdevpdfi.c 2008-06-24 14:16:29 UTC (rev 8803)
@@ -68,7 +68,6 @@
/* Define the structure for keeping track of progress through an image. */
typedef struct pdf_image_enum_s {
gx_image_enum_common;
- gs_memory_t *memory;
int width;
int bits_per_pixel; /* bits per pixel (per plane) */
int rows_left;
@@ -1106,7 +1105,7 @@
code = pdf_end_and_do_image(pdev, &pie->writer, &pie->mat, info->id, do_image);
pie->writer.alt_writer_count--; /* For GC. */
}
- gs_free_object(pie->memory, pie, "pdf_end_image");
+ gx_image_free_enum(&info);
return code;
}
Modified: trunk/gs/src/gdevplnx.c
===================================================================
--- trunk/gs/src/gdevplnx.c 2008-06-22 09:47:49 UTC (rev 8802)
+++ trunk/gs/src/gdevplnx.c 2008-06-24 14:16:29 UTC (rev 8803)
@@ -811,7 +811,6 @@
/* Define the state for image rendering. */
typedef struct plane_image_enum_s {
gx_image_enum_common;
- gs_memory_t *memory;
gx_image_enum_common_t *info; /* plane device enumerator */
const gs_imager_state *pis; /* original imager state */
gs_imager_state *pis_image; /* modified imager state */
@@ -1013,7 +1012,7 @@
gs_free_object(ppie->memory, ppie->pis_image,
"plane_image_end_image(pis_image)");
- gs_free_object(ppie->memory, info, "plane_image_end_image(info)");
+ gx_image_free_enum(&info);
return code;
}
Modified: trunk/gs/src/gdevpx.c
===================================================================
--- trunk/gs/src/gdevpx.c 2008-06-22 09:47:49 UTC (rev 8802)
+++ trunk/gs/src/gdevpx.c 2008-06-24 14:16:29 UTC (rev 8803)
@@ -20,6 +20,7 @@
#include "gserrors.h"
#include "gsccolor.h"
#include "gsdcolor.h"
+#include "gxiparam.h"
#include "gxcspace.h" /* for color mapping for images */
#include "gxdevice.h"
#include "gxpath.h"
@@ -1705,7 +1706,7 @@
if (pie->y > pie->rows.first_y && draw_last)
code = pclxl_image_write_rows(pie);
gs_free_object(pie->memory, pie->rows.data, "pclxl_end_image(rows)");
- gs_free_object(pie->memory, pie, "pclxl_end_image");
+ gx_image_free_enum(&info);
return code;
}
Modified: trunk/gs/src/gdevtrac.c
===================================================================
--- trunk/gs/src/gdevtrac.c 2008-06-22 09:47:49 UTC (rev 8802)
+++ trunk/gs/src/gdevtrac.c 2008-06-24 14:16:29 UTC (rev 8803)
@@ -351,7 +351,7 @@
{
trace_image_enum_t *pie = (trace_image_enum_t *)info;
- gs_free_object(pie->memory, pie, "trace_end_image");
+ gx_image_free_enum(&info);
return 0;
}
static const gx_image_enum_procs_t trace_image_enum_procs = {
Modified: trunk/gs/src/gdevvec.c
===================================================================
--- trunk/gs/src/gdevvec.c 2008-06-22 09:47:49 UTC (rev 8802)
+++ trunk/gs/src/gdevvec.c 2008-06-24 14:16:29 UTC (rev 8803)
@@ -24,6 +24,7 @@
#include "gxfixed.h"
#include "gdevvec.h"
#include "gscspace.h"
+#include "gxiparam.h"
#include "gxdcolor.h"
#include "gxpaint.h" /* requires gx_path, ... */
#include "gzpath.h"
@@ -912,7 +913,7 @@
if (bcode < 0)
code = bcode;
}
- gs_free_object(pie->memory, pie, "gdev_vector_end_image");
+ gx_image_free_enum((gx_image_enum_common_t **)&pie);
return code;
}
Modified: trunk/gs/src/gdevvec.h
===================================================================
--- trunk/gs/src/gdevvec.h 2008-06-22 09:47:49 UTC (rev 8802)
+++ trunk/gs/src/gdevvec.h 2008-06-24 14:16:29 UTC (rev 8803)
@@ -338,7 +338,6 @@
#define gdev_vector_image_enum_common\
gx_image_enum_common;\
/* Set by begin_image */\
- gs_memory_t *memory; /* from begin_image */\
gx_image_enum_common_t *default_info; /* non-0 iff using default implementation */\
gx_image_enum_common_t *bbox_info; /* non-0 iff passing image data to bbox dev */\
int width, height;\
Modified: trunk/gs/src/gsimage.h
===================================================================
--- trunk/gs/src/gsimage.h 2008-06-22 09:47:49 UTC (rev 8802)
+++ trunk/gs/src/gsimage.h 2008-06-24 14:16:29 UTC (rev 8803)
@@ -116,10 +116,10 @@
typedef struct gx_image_enum_common_s gx_image_enum_common_t;
#endif
+typedef struct gs_image_enum_s gs_image_enum;
int gs_image_begin_typed(const gs_image_common_t * pic, gs_state * pgs,
bool uses_color, gx_image_enum_common_t ** ppie);
-typedef struct gs_image_enum_s gs_image_enum;
gs_image_enum *gs_image_enum_alloc(gs_memory_t *, client_name_t);
/*
Modified: trunk/gs/src/gxclimag.c
===================================================================
--- trunk/gs/src/gxclimag.c 2008-06-22 09:47:49 UTC (rev 8802)
+++ trunk/gs/src/gxclimag.c 2008-06-24 14:16:29 UTC (rev 8803)
@@ -222,7 +222,6 @@
typedef struct clist_image_enum_s {
gx_image_enum_common;
/* Arguments of begin_image */
- gs_memory_t *memory;
gs_pixel_image_t image; /* only uses Width, Height, Interpolate */
gx_drawing_color dcolor; /* only pure right now */
gs_int_rect rect;
@@ -848,7 +847,7 @@
}
--cdev->driver_call_nesting;
cdev->image_enum_id = gs_no_id;
- gs_free_object(pie->memory, pie, "clist_image_end_image");
+ gx_image_free_enum(&info);
return code;
}
Modified: trunk/gs/src/gxidata.c
===================================================================
--- trunk/gs/src/gxidata.c 2008-06-22 09:47:49 UTC (rev 8802)
+++ trunk/gs/src/gxidata.c 2008-06-24 14:16:29 UTC (rev 8803)
@@ -464,6 +464,6 @@
}
gs_free_object(mem, penum->line, "image line");
gs_free_object(mem, penum->buffer, "image buffer");
- gs_free_object(mem, penum, "gx_default_end_image");
+ gx_image_free_enum(&info);
return 0;
}
Modified: trunk/gs/src/gximag3x.c
===================================================================
--- trunk/gs/src/gximag3x.c 2008-06-22 09:47:49 UTC (rev 8802)
+++ trunk/gs/src/gximag3x.c 2008-06-24 14:16:29 UTC (rev 8803)
@@ -95,7 +95,6 @@
gx_device *pcdev; /* gx_device_mask_clip in default impl. */
int num_components; /* (not counting masks) */
int bpc; /* pixel BitsPerComponent */
- gs_memory_t *memory;
#define NUM_MASKS 2 /* opacity, shape */
image3x_channel_state_t mask[NUM_MASKS], pixel;
} gx_image3x_enum_t;
@@ -855,6 +854,6 @@
gs_free_object(mem, pcdev, "gx_image3x_end_image(pcdev)");
gs_free_object(mem, mdev0, "gx_image3x_end_image(mask[0].mdev)");
gs_free_object(mem, mdev1, "gx_image3x_end_image(mask[1].mdev)");
- gs_free_object(mem, penum, "gx_image3x_end_image");
+ gx_image_free_enum(&info);
return (pcode < 0 ? pcode : scode < 0 ? scode : ocode);
}
Modified: trunk/gs/src/gximage.h
===================================================================
--- trunk/gs/src/gximage.h 2008-06-22 09:47:49 UTC (rev 8802)
+++ trunk/gs/src/gximage.h 2008-06-24 14:16:29 UTC (rev 8803)
@@ -202,7 +202,6 @@
irender_proc((*render));
const gs_imager_state *pis;
const gs_color_space *pcs; /* color space of image */
- gs_memory_t *memory;
byte *buffer; /* for expanding samples to a */
/* byte or frac */
uint buffer_size;
Modified: trunk/gs/src/gximage1.c
===================================================================
--- trunk/gs/src/gximage1.c 2008-06-22 09:47:49 UTC (rev 8802)
+++ trunk/gs/src/gximage1.c 2008-06-24 14:16:29 UTC (rev 8803)
@@ -201,3 +201,30 @@
{
gx_pixel_image_release((gs_pixel_image_t *)pic, mem);
}
+
+/* Free the image enumerator. */
+void
+gx_image_free_enum(gx_image_enum_common_t **ppenum)
+{
+ gx_image_enum_common_t * penum = *ppenum;
+ gs_memory_t *mem = penum->memory;
+
+ /* Bug 688845 comment #38 :
+ Adobe Illustrator creates a Postscript document,
+ in which an image data procedure executes 'save',
+ and the corresponding 'restore' appears after the image end.
+ It causes this procedure is called at a higher save level than
+ at which the enumerator was allocated, so that gs_free_object below
+ works idle. Nevertheless we can't leave pointers in the structure,
+ because they may point to blocks already released
+ by the client's subclass method for end_image.
+ Leaving them uncleaned caused a real crash in the garbager - see bug 688845.
+ So we clean the entire subclassed enumerator here,
+ rather this is a generic function for base class.
+ Note the cleaning is neccessaryfor Postscript only,
+ because other languaged don't implement save-restore.
+ */
+ memset(penum, 0, gs_object_size(mem, penum));
+ gs_free_object(mem, penum, "gx_image_free_enum");
+ *ppenum = NULL;
+}
Modified: trunk/gs/src/gximage3.c
===================================================================
--- trunk/gs/src/gximage3.c 2008-06-22 09:47:49 UTC (rev 8802)
+++ trunk/gs/src/gximage3.c 2008-06-24 14:16:29 UTC (rev 8803)
@@ -74,7 +74,6 @@
gs_image3_interleave_type_t InterleaveType;
int num_components; /* (not counting mask) */
int bpc; /* BitsPerComponent */
- gs_memory_t *memory;
int mask_width, mask_height, mask_full_height;
int pixel_width, pixel_height, pixel_full_height;
byte *mask_data; /* (if chunky) */
@@ -739,6 +738,6 @@
"gx_image3_end_image(pixel_data)");
gs_free_object(mem, pcdev, "gx_image3_end_image(pcdev)");
gs_free_object(mem, mdev, "gx_image3_end_image(mdev)");
- gs_free_object(mem, penum, "gx_image3_end_image");
+ gx_image_free_enum(&info);
return (pcode < 0 ? pcode : mcode < 0 ? mcode : code1 < 0 ? code1 : code2);
}
Modified: trunk/gs/src/gxiparam.h
===================================================================
--- trunk/gs/src/gxiparam.h 2008-06-22 09:47:49 UTC (rev 8802)
+++ trunk/gs/src/gxiparam.h 2008-06-24 14:16:29 UTC (rev 8803)
@@ -213,6 +213,7 @@
const gx_image_type_t *image_type;\
const gx_image_enum_procs_t *procs;\
gx_device *dev;\
+ gs_memory_t *memory; /* from begin_image */\
gs_id id;\
bool skipping; /* don't render, just consume image streams. */\
int num_planes;\
@@ -252,4 +253,7 @@
image_enum_proc_end_image(gx_image1_end_image);
image_enum_proc_flush(gx_image1_flush);
+/* Free the image enumerator. */
+void gx_image_free_enum(gx_image_enum_common_t **ppenum);
+
#endif /* gxiparam_INCLUDED */
Modified: trunk/gs/src/lib.mak
===================================================================
--- trunk/gs/src/lib.mak 2008-06-22 09:47:49 UTC (rev 8802)
+++ trunk/gs/src/lib.mak 2008-06-24 14:16:29 UTC (rev 8803)
@@ -1788,7 +1788,7 @@
$(GLOBJ)gdevvec.$(OBJ) : $(GLSRC)gdevvec.c $(GXERR)\
$(math__h) $(memory__h) $(string__h)\
- $(gdevvec_h) $(gp_h) $(gscspace_h) $(gsparam_h) $(gsutil_h)\
+ $(gdevvec_h) $(gp_h) $(gscspace_h) $(gxiparam_h) $(gsparam_h) $(gsutil_h)\
$(gxdcolor_h) $(gxfixed_h) $(gxpaint_h)\
$(gzcpath_h) $(gzpath_h)
$(GLCC) $(GLO_)gdevvec.$(OBJ) $(C_) $(GLSRC)gdevvec.c
More information about the gs-cvs
mailing list