Start here

Home
About Klocwork
What's new
Fixed issues
Release notes
Installation

Reference

C/C++ checkers
Java checkers
C# checkers
MISRA C 2004 checkers
MISRA C++ 2008 checkers
MISRA C 2012 checkers
MISRA C 2012 checkers with Amendment 1
Commands
Metrics
Troubleshooting
Reference

Product components

C/C++ Integration build analysis
Java Integration build analysis
Desktop analysis
Refactoring
Klocwork Static Code Analysis
Klocwork Code Review
Structure101
Tuning
Custom checkers

Coding environments

Visual Studio
Eclipse for C/C++
Eclipse for Java
IntelliJ IDEA
Other

Administration

Project configuration
Build configuration
Administration
Analysis performance
Server performance
Security/permissions
Licensing
Klocwork Static Code Analysis Web API
Klocwork Code Review Web API

Community

View help online
Visit RogueWave.com
Klocwork Support
Rogue Wave Videos

Legal

Legal information

ANDROID.UF.CAMERA

UF (Use Freed) issues are reported when there is an attempt to use resources after they were released. The ANDROID.UF.CAMERA warning indicates an attempt to use Camera after it was released.

Example 1

21     private Camera camera;
22 
23     private void initCamera() {
24         camera = Camera.open();
25     }
26 
27     public boolean onKeyDown(final int keyCode, final KeyEvent event) {
28         if (keyCode == KeyEvent.KEYCODE_DPAD_CENTER) {
29             if (camera != null) {
30                 final CameraPictureCallbackImpl callback = new CameraPictureCallbackImpl();
31                 camera.takePicture(null, null, callback);
32             }
33             return true;
34         }
35         return super.onKeyDown(keyCode, event);
36     }
37 
38     private class CameraPictureCallbackImpl implements Camera.PictureCallback {
39         private Bitmap bitmap;
40 
41         public void onPictureTaken(final byte[] bytes, final Camera camera) {
42             camera.stopPreview();
43             camera.release();
44             bitmap = BitmapFactory.decodeByteArray(bytes, 0, bytes.length);
45             if (bitmap == null) {
46                 camera.startPreview();
47             }
48         }
49 
50         public Bitmap getBitmap() {
51             return bitmap;
52         }
53     }

ANDROID.UF.CAMERA is reported for the snippet on line 46 since callback method 'onPictureTaken(...)' starts the camera preview even if the camera was released on line 43.

Extension

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