summaryrefslogtreecommitdiff
path: root/fitz/base_hash.c
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/base_hash.c
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/base_hash.c')
-rw-r--r--fitz/base_hash.c4
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;