summaryrefslogtreecommitdiff
path: root/fitz
diff options
context:
space:
mode:
authorzeniko <zeniko@gmail.com>2013-06-01 21:25:24 +0200
committerRobin Watts <robin.watts@artifex.com>2013-06-03 16:22:03 +0100
commita727aacc2d4feb0c6f5c609e05a0d5611aa97292 (patch)
treedcfa91eab09c716ac38a8ea114221934a758ad62 /fitz
parent9820d3cf35e8ba4a88c2be90f3ca6c651b03bbe1 (diff)
downloadmupdf-a727aacc2d4feb0c6f5c609e05a0d5611aa97292.tar.xz
prevent deadlock under memory pressure
In multiple places, between acquiring and releasing the FREETYPE lock, exceptions may be thrown which aren't caught in order to properly release the lock. This patch introduces the necessary fz_try/fz_always/ fz_catch invocations to prevent a potential deadlock in these situations. RJW: Also fix another problem pointed out by zeniko. Thanks!
Diffstat (limited to 'fitz')
-rw-r--r--fitz/base_hash.c4
-rw-r--r--fitz/res_font.c31
2 files changed, 29 insertions, 6 deletions
diff --git a/fitz/base_hash.c b/fitz/base_hash.c
index 1da8cac9..22b64ec6 100644
--- a/fitz/base_hash.c
+++ b/fitz/base_hash.c
@@ -160,7 +160,7 @@ fz_resize_hash(fz_context *ctx, fz_hash_table *table, int newsize)
if (table->lock == FZ_LOCK_ALLOC)
fz_unlock(ctx, FZ_LOCK_ALLOC);
- newents = fz_malloc_array(ctx, newsize, sizeof(fz_hash_entry));
+ newents = fz_malloc_array_no_throw(ctx, newsize, sizeof(fz_hash_entry));
if (table->lock == FZ_LOCK_ALLOC)
fz_lock(ctx, FZ_LOCK_ALLOC);
if (table->lock >= 0)
@@ -176,6 +176,8 @@ fz_resize_hash(fz_context *ctx, fz_hash_table *table, int newsize)
return;
}
}
+ if (newents == NULL)
+ fz_throw(ctx, "hash table resize failed; out of memory (%d entries)", newsize);
table->ents = newents;
memset(table->ents, 0, sizeof(fz_hash_entry) * newsize);
table->size = newsize;
diff --git a/fitz/res_font.c b/fitz/res_font.c
index 8fb51377..3263f88c 100644
--- a/fitz/res_font.c
+++ b/fitz/res_font.c
@@ -515,8 +515,19 @@ retry_unhinted:
return NULL;
}
- result = fz_copy_ft_bitmap(ctx, face->glyph->bitmap_left, face->glyph->bitmap_top, &face->glyph->bitmap);
- fz_unlock(ctx, FZ_LOCK_FREETYPE);
+ fz_try(ctx)
+ {
+ result = fz_copy_ft_bitmap(ctx, face->glyph->bitmap_left, face->glyph->bitmap_top, &face->glyph->bitmap);
+ }
+ fz_always(ctx)
+ {
+ fz_unlock(ctx, FZ_LOCK_FREETYPE);
+ }
+ fz_catch(ctx)
+ {
+ fz_rethrow(ctx);
+ }
+
return result;
}
@@ -623,9 +634,19 @@ fz_render_ft_stroked_glyph(fz_context *ctx, fz_font *font, int gid, const fz_mat
}
bitmap = (FT_BitmapGlyph)glyph;
- pixmap = fz_copy_ft_bitmap(ctx, bitmap->left, bitmap->top, &bitmap->bitmap);
- FT_Done_Glyph(glyph);
- fz_unlock(ctx, FZ_LOCK_FREETYPE);
+ fz_try(ctx)
+ {
+ pixmap = fz_copy_ft_bitmap(ctx, bitmap->left, bitmap->top, &bitmap->bitmap);
+ }
+ fz_always(ctx)
+ {
+ FT_Done_Glyph(glyph);
+ fz_unlock(ctx, FZ_LOCK_FREETYPE);
+ }
+ fz_catch(ctx)
+ {
+ fz_rethrow(ctx);
+ }
return pixmap;
}