diff options
author | zeniko <zeniko@gmail.com> | 2013-06-01 21:25:24 +0200 |
---|---|---|
committer | Robin Watts <robin.watts@artifex.com> | 2013-06-03 16:22:03 +0100 |
commit | a727aacc2d4feb0c6f5c609e05a0d5611aa97292 (patch) | |
tree | dcfa91eab09c716ac38a8ea114221934a758ad62 /fitz/base_hash.c | |
parent | 9820d3cf35e8ba4a88c2be90f3ca6c651b03bbe1 (diff) | |
download | mupdf-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/base_hash.c')
-rw-r--r-- | fitz/base_hash.c | 4 |
1 files changed, 3 insertions, 1 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; |