From bcf7519882ba6f7b8f4b8047fb1f94bc9bd1ec6e Mon Sep 17 00:00:00 2001 From: Robin Watts Date: Thu, 1 Mar 2012 16:38:01 +0000 Subject: 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. --- fitz/res_store.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'fitz') 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 */ -- cgit v1.2.3