ANDROID.UF.BITMAP

UF (Use Freed) issues are reported when there is an attempt to use resources after they were released. The ANDROID.UF.BITMAP warning indicates an attempt to get pixel(s) from a Bitmap or set pixel(s) into a Bitmap after it was recycled.

Example 1

Copy
     public void addWatermark(final byte[] data) {
         final Bitmap bmp = loadBitmap(data);
         if (bmp != null) {
             final int width = bmp.getWidth();
             for (int i = 0; i < width; i++) {
                 bmp.setPixel(i, i, Color.argb(255, 0, 0, 0));
             }
         }
     }
 
     private Bitmap loadBitmap(byte[] data) {
         final Bitmap bmp = BitmapFactory.decodeByteArray(data, 0, data.length);
         if (bmp == null) {
             Log.d(TAG, "Was not able to decode an image");
         }
 
         final int width = bmp.getWidth();
         final int height = bmp.getHeight();
         if (width <= 3 || height <= 3 ) {
             bmp.recycle();
         }
         return bmp;
     }

ANDROID.UF.BITMAP is reported for the snippet on line 24 since method 'loadBitmap()' recycles the bitmap if one of its dimensions is less than '3' (line 38).

Extension

This checker can be extended through the Klocwork knowledge base. See Tuning Java analysis for more information.