[gs-cvs] rev 7767 - trunk/gs/src
leonardo at ghostscript.com
leonardo at ghostscript.com
Tue Mar 6 06:35:01 PST 2007
Author: leonardo
Date: 2007-03-06 06:35:00 -0800 (Tue, 06 Mar 2007)
New Revision: 7767
Modified:
trunk/gs/src/gsfont.c
trunk/gs/src/gxfcache.h
trunk/gs/src/gxttfb.c
trunk/gs/src/ttfmain.c
trunk/gs/src/ttfmemd.c
trunk/gs/src/ttobjs.c
trunk/gs/src/ttobjs.h
Log:
Fix (TT interpreter) : memory leaks with PCL.
DETAILS :
1. The old code created gx_ttfMemory instance per font,
but only the first one is used. Others are leaks.
The new code create one instance per font directory.
The new field gs_font_dir::ttm works for that.
2. For proper lock count on memory errors, don't call Context_Destroy
if Context_Create was not called.
3. In ttobjs.c don't use exec->current_face for accessing ttfMemory,
because PCL closes fonts when they are not active
in the TT interpreter. The new field Execution_Context::memory
works for that.
EXPECTED DIFFERENCES :
None.
Modified: trunk/gs/src/gsfont.c
===================================================================
--- trunk/gs/src/gsfont.c 2007-03-05 21:50:20 UTC (rev 7766)
+++ trunk/gs/src/gsfont.c 2007-03-06 14:35:00 UTC (rev 7767)
@@ -265,6 +265,7 @@
pdir->grid_fit_tt = 2;
pdir->memory = struct_mem;
pdir->tti = 0;
+ pdir->ttm = 0;
pdir->san = 0;
pdir->global_glyph_code = NULL;
pdir->text_enum_id = 0;
Modified: trunk/gs/src/gxfcache.h
===================================================================
--- trunk/gs/src/gxfcache.h 2007-03-05 21:50:20 UTC (rev 7766)
+++ trunk/gs/src/gxfcache.h 2007-03-06 14:35:00 UTC (rev 7767)
@@ -52,6 +52,10 @@
# define ttfInterpreter_DEFINED
typedef struct ttfInterpreter_s ttfInterpreter;
#endif
+#ifndef gx_ttfMemory_DEFINED
+# define gx_ttfMemory_DEFINED
+typedef struct gx_ttfMemory_s gx_ttfMemory;
+#endif
#ifndef gx_device_spot_analyzer_DEFINED
# define gx_device_spot_analyzer_DEFINED
typedef struct gx_device_spot_analyzer_s gx_device_spot_analyzer;
@@ -305,6 +309,7 @@
/* An allocator for extension structures */
gs_memory_t *memory;
ttfInterpreter *tti;
+ gx_ttfMemory *ttm;
/* User parameter GridFitTT. */
uint grid_fit_tt;
gx_device_spot_analyzer *san;
@@ -320,8 +325,8 @@
#define font_dir_do_ptrs(m)\
/*m(-,orig_fonts)*/ m(0,scaled_fonts) m(1,fmcache.mdata)\
m(2,ccache.table) m(3,ccache.mark_glyph_data)\
- m(4,glyph_to_unicode_table) m(5,tti) m(6,san)
-#define st_font_dir_max_ptrs 7
+ m(4,glyph_to_unicode_table) m(5,tti) m(6,ttm) m(7,san)
+#define st_font_dir_max_ptrs 8
/* Character cache procedures (in gxccache.c and gxccman.c) */
int gx_char_cache_alloc(gs_memory_t * struct_mem, gs_memory_t * bits_mem,
Modified: trunk/gs/src/gxttfb.c
===================================================================
--- trunk/gs/src/gxttfb.c 2007-03-05 21:50:20 UTC (rev 7766)
+++ trunk/gs/src/gxttfb.c 2007-03-06 14:35:00 UTC (rev 7767)
@@ -369,23 +369,27 @@
ttfFont *ttfFont__create(gs_font_dir *dir)
{
gs_memory_t *mem = dir->memory;
- gx_ttfMemory *m = gs_alloc_struct(mem, gx_ttfMemory, &st_gx_ttfMemory, "ttfFont__create");
ttfFont *ttf;
- if (!m)
+ if (dir->ttm == NULL) {
+ gx_ttfMemory *m = gs_alloc_struct(mem, gx_ttfMemory, &st_gx_ttfMemory, "ttfFont__create(gx_ttfMemory)");
+
+ if (!m)
+ return 0;
+ m->super.alloc_struct = gx_ttfMemory__alloc_struct;
+ m->super.alloc_bytes = gx_ttfMemory__alloc_bytes;
+ m->super.free = gx_ttfMemory__free;
+ m->memory = mem;
+ dir->ttm = m;
+ }
+ if(ttfInterpreter__obtain(&dir->ttm->super, &dir->tti))
return 0;
- m->super.alloc_struct = gx_ttfMemory__alloc_struct;
- m->super.alloc_bytes = gx_ttfMemory__alloc_bytes;
- m->super.free = gx_ttfMemory__free;
- m->memory = mem;
- if(ttfInterpreter__obtain(&m->super, &dir->tti))
- return 0;
if(gx_san__obtain(mem->stable_memory, &dir->san))
return 0;
ttf = gs_alloc_struct(mem, ttfFont, &st_ttfFont, "ttfFont__create");
if (ttf == NULL)
return 0;
- ttfFont__init(ttf, &m->super, DebugRepaint, (gs_debug_c('Y') ? DebugPrint : NULL));
+ ttfFont__init(ttf, &dir->ttm->super, DebugRepaint, (gs_debug_c('Y') ? DebugPrint : NULL));
return ttf;
}
@@ -393,10 +397,15 @@
{
ttfMemory *mem = this->tti->ttf_memory;
+ /* assert(mem == &dir->ttm->super); */
ttfFont__finit(this);
mem->free(mem, this, "ttfFont__destroy");
ttfInterpreter__release(&dir->tti);
gx_san__release(&dir->san);
+ if (dir->tti == NULL && dir->ttm != NULL) {
+ dir->ttm = NULL;
+ mem->free(mem, mem, "ttfFont__destroy(gx_ttfMemory)");
+ }
}
int ttfFont__Open_aux(ttfFont *this, ttfInterpreter *tti, gx_ttfReader *r, gs_font_type42 *pfont,
Modified: trunk/gs/src/ttfmain.c
===================================================================
--- trunk/gs/src/ttfmain.c 2007-03-05 21:50:20 UTC (rev 7766)
+++ trunk/gs/src/ttfmain.c 2007-03-06 14:35:00 UTC (rev 7767)
@@ -173,7 +173,6 @@
mem->free(mem, tti->usage, "ttfInterpreter__release");
mem->free(mem, tti->exec, "ttfInterpreter__release");
mem->free(mem, *ptti, "ttfInterpreter__release");
- mem->free(mem, mem, "ttfInterpreter__release");
*ptti = 0;
}
@@ -191,8 +190,15 @@
void ttfFont__finit(ttfFont *this)
{ ttfMemory *mem = this->tti->ttf_memory;
- if (this->exec)
- Context_Destroy(this->exec);
+ if (this->exec) {
+ if (this->inst)
+ Context_Destroy(this->exec);
+ else {
+ /* Context_Create was not called - see ttfFont__Open.
+ Must not call Context_Destroy for proper 'lock' count.
+ */
+ }
+ }
this->exec = NULL;
if (this->inst)
Instance_Destroy(this->inst);
Modified: trunk/gs/src/ttfmemd.c
===================================================================
--- trunk/gs/src/ttfmemd.c 2007-03-05 21:50:20 UTC (rev 7766)
+++ trunk/gs/src/ttfmemd.c 2007-03-06 14:35:00 UTC (rev 7767)
@@ -84,6 +84,7 @@
ENUM_PTR(19, TExecution_Context, twilight.touch);
ENUM_PTR(20, TExecution_Context, twilight.contours);
ENUM_PTR(21, TExecution_Context, cvt);
+ ENUM_PTR(22, TExecution_Context, memory);
ENUM_PTRS_END
private RELOC_PTRS_WITH(TExecution_Context_reloc_ptrs, TExecution_Context *mptr)
@@ -115,6 +116,7 @@
RELOC_PTR(TExecution_Context, twilight.touch);
RELOC_PTR(TExecution_Context, twilight.contours);
RELOC_PTR(TExecution_Context, cvt);
+ RELOC_PTR(TExecution_Context, memory);
DISCARD(mptr);
}
RELOC_PTRS_END
Modified: trunk/gs/src/ttobjs.c
===================================================================
--- trunk/gs/src/ttobjs.c 2007-03-05 21:50:20 UTC (rev 7766)
+++ trunk/gs/src/ttobjs.c 2007-03-06 14:35:00 UTC (rev 7767)
@@ -232,17 +232,12 @@
if ( !exec )
return TT_Err_Ok;
- if ( !exec->current_face ) {
- /* This may happen while closing a high level device, when allocator runs out of memory.
- A test case is 01_001.pdf with pdfwrite and a small vmthreshold.
- */
- return TT_Err_Out_Of_Memory;
- }
if (--exec->lock)
return TT_Err_Ok; /* Still in use */
+ mem = exec->memory;
+ if (!mem)
+ return TT_Err_Ok; /* Never used */
- mem = exec->current_face->font->tti->ttf_memory;
-
/* points zone */
FREE( exec->pts.cur_y );
FREE( exec->pts.cur_x );
@@ -304,6 +299,7 @@
Int callSize, stackSize;
callSize = 32;
+ exec->memory = mem;
/* reserve a little extra for broken fonts like courbs or timesbs */
stackSize = maxp->maxStackElements + 32;
Modified: trunk/gs/src/ttobjs.h
===================================================================
--- trunk/gs/src/ttobjs.h 2007-03-05 21:50:20 UTC (rev 7766)
+++ trunk/gs/src/ttobjs.h 2007-03-06 14:35:00 UTC (rev 7767)
@@ -695,6 +695,7 @@
Int n_points;
Int maxGlyphSize;
Int lock;
+ ttfMemory *memory;
};
More information about the gs-cvs
mailing list