diff options
author | Ken Sharp <ken.sharp@artifex.com> | 2012-05-14 13:35:51 +0100 |
---|---|---|
committer | Ken Sharp <ken.sharp@artifex.com> | 2012-05-14 13:36:25 +0100 |
commit | 8ea8d0df81d2552a3470bbf708b91fb4467a5be2 (patch) | |
tree | 0db10669ba324edb174b507bb97c7b8f99d12109 | |
parent | 6b31a6466c0819db229cbde420c72789eecdbe2d (diff) |
pdfwrite - memory fixes. don't track pdf_font_cache in GS fonts
pdfwrite maintains a 'font cache' of PDF font objects which are related to
GS fonts. Previously these were tracked by adding a pointer to the GS font,
and freeing the memory when the font was unloaded, by using the gs_notify_register
callback.
This causes problems when we are in 'file per page' mode. We want to discard
and rebuild the font cache at the end of each page, so we don't try to
reuse font objects. But if we discard the memory, the font is still pointing
at it. This causes later memory problems.
The simplest solution is to stop tracking the elements in the GS fonts. This
means that an element will persist and be stale after the font goes out of
scope, but its a fairly small amount of memory per font. We now clean up the
PDF font cache and all the elements in pdf_close along with all the other memory.
The 'file per page' mode using the '-sOutputFilename=%d.pdf' syntax now seems
to work correctly. There does not seem to be any great amount of memory leakage
now either.
The next step is to implement a 'server' mode application and use that to
check that there are no remaining memory leaks
No differences expected
-rw-r--r-- | gs/base/gdevpdtt.c | 26 |
1 files changed, 12 insertions, 14 deletions
diff --git a/gs/base/gdevpdtt.c b/gs/base/gdevpdtt.c index 517c95749..3fa5e4bfd 100644 --- a/gs/base/gdevpdtt.c +++ b/gs/base/gdevpdtt.c @@ -785,10 +785,18 @@ alloc_font_cache_elem_arrays(gx_device_pdf *pdev, pdf_font_cache_elem_t *e, int pdf_free_font_cache(gx_device_pdf *pdev) { - /* fixme : release elements. */ - /* Should not need to be fixed. The elements are released when the - * font is finalized by the garbage collector + pdf_font_cache_elem_t *e = pdev->font_cache, *next; + + /* fixed! fixme : release elements. + * We no longer track font_cache elements in the original font, which is where + * the memory used to be released. So now we must release it ourselves. */ + + while (e != NULL) { + next = e->next; + pdf_remove_font_cache_elem(e); + e = next; + } pdev->font_cache = NULL; return 0; } @@ -823,14 +831,6 @@ pdf_attached_font_resource(gx_device_pdf *pdev, gs_font *font, return 0; } -static int -pdf_notify_remove_font(void *proc_data, void *event_data) -{ /* gs_font_finalize passes event_data == NULL, so check it here. */ - if (event_data == NULL) - pdf_remove_font_cache_elem((pdf_font_cache_elem_t *)proc_data); - return 0; -} - /* * Attach font resource to a font. */ @@ -875,9 +875,7 @@ pdf_attach_font_resource(gx_device_pdf *pdev, gs_font *font, e->pdev = pdev; e->next = pdev->font_cache; pdev->font_cache = e; - code = gs_notify_register(&font->notify_list, pdf_notify_remove_font, e); - if (code < 0) - return code; + return 0; } return 0; } |