chrisbanes / Android-BitmapCache

Android-BitmapCache is a specialised cache, for use with Android Bitmap objects.
834 stars 224 forks source link

Race condition in CacheableImageView.java #17

Closed nikclayton closed 11 years ago

nikclayton commented 11 years ago

I think there's a race condition here.

https://github.com/chrisbanes/Android-BitmapCache/blob/master/library/src/uk/co/senab/bitmapcache/CacheableImageView.java#L51

This code calls setImageDrawable() before the reference count is incremented by setBeingUsed(). The race is that if the drawable is evicted from the cache due to memory pressure after the drawable is assigned but before the reference count is incremented then checkState() might be called from another thread, and the bitmap might be recycled, leading to the "Canvas trying to use a recycled bitmap" exception.