From 565644e616ea64f97769d8939beb155f4031da2f Mon Sep 17 00:00:00 2001 From: Chris Wilson Date: Thu, 19 Jun 2008 11:42:43 +0100 Subject: [PATCH] [cairo-pattern] Band-aid for the solid surface cache. Behdad noticed that the mixing of dissimilar surfaces within the cache was fubar (http://lists.cairographics.org/archives/cairo/2008-June/014348.html). This corrects the dereferencing of the evicted surface, but leaves open the question of the future of the cache. --- src/cairo-pattern.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/cairo-pattern.c b/src/cairo-pattern.c index 89e92ca74..b9f068a63 100644 --- a/src/cairo-pattern.c +++ b/src/cairo-pattern.c @@ -1453,9 +1453,10 @@ _cairo_pattern_acquire_surface_for_solid (cairo_solid_pattern_t *pattern, &pattern->base); if (status) goto UNLOCK; + + cairo_surface_reference (surface); } else { /* Unable to reuse, evict */ - cairo_surface_destroy (surface); surface = NULL; } } @@ -1485,6 +1486,7 @@ _cairo_pattern_acquire_surface_for_solid (cairo_solid_pattern_t *pattern, i = solid_surface_cache.size++; solid_surface_cache.cache[i].color = pattern->color; + cairo_surface_destroy (solid_surface_cache.cache[i].surface); solid_surface_cache.cache[i].surface = surface; DONE: @@ -1513,8 +1515,11 @@ _cairo_pattern_reset_solid_surface_cache (void) /* remove surfaces starting from the end so that solid_surface_cache.cache * is always in a consistent state when we release the mutex. */ while (solid_surface_cache.size) { - cairo_surface_t *surface = solid_surface_cache.cache[solid_surface_cache.size-1].surface; + cairo_surface_t *surface; + solid_surface_cache.size--; + surface = solid_surface_cache.cache[solid_surface_cache.size].surface; + solid_surface_cache.cache[solid_surface_cache.size].surface = NULL; /* release the lock to avoid the possibility of a recursive * deadlock when the scaled font destroy closure gets called */