diff options
author | Robin Watts <robin.watts@artifex.com> | 2012-03-01 16:38:01 +0000 |
---|---|---|
committer | Robin Watts <robin.watts@artifex.com> | 2012-03-01 16:38:01 +0000 |
commit | bcf7519882ba6f7b8f4b8047fb1f94bc9bd1ec6e (patch) | |
tree | d1442f846e9e46edac46d692f6044b9b1c85e660 /fitz/res_store.c | |
parent | c6aa389a2c3430396a5e818bbb849410ab29d617 (diff) | |
download | mupdf-bcf7519882ba6f7b8f4b8047fb1f94bc9bd1ec6e.tar.xz |
Fix incorrect handling of race condition.
When inserting an item into the store we check for an identically
keyed item being there already (for instance a pixmap created from
an image I at factor F may find that such a pixmap has already been
inserted). The correct thing to do is to return the old one so we
can use that in preference.
The code was attempting to do this, but was returning a pointer
to the fz_item rather than to the item->val. Fixed here.
Diffstat (limited to 'fitz/res_store.c')
-rw-r--r-- | fitz/res_store.c | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/fitz/res_store.c b/fitz/res_store.c index 8f9c1ad8..0e3e7214 100644 --- a/fitz/res_store.c +++ b/fitz/res_store.c @@ -248,7 +248,7 @@ fz_store_item(fz_context *ctx, void *key, void *val_, unsigned int itemsize, fz_ /* If we can index it fast, put it into the hash table */ if (use_hash) { - fz_pixmap *existing; + fz_item *existing; fz_try(ctx) { @@ -265,7 +265,8 @@ fz_store_item(fz_context *ctx, void *key, void *val_, unsigned int itemsize, fz_ if (existing) { fz_unlock(ctx, FZ_LOCK_ALLOC); - return existing; + fz_free(ctx, item); + return existing->val; } } /* Now we can never fail, bump the ref */ |