ANDROID.UF.MEDIARECORDER

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

Example 1

Copy
     public boolean onKeyDown(final int keyCode, final KeyEvent event) {
         if (keyCode == KeyEvent.KEYCODE_DPAD_CENTER) {
             MediaRecorder mRecorder = new MediaRecorder();
 
             mRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
             mRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
             mRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
 
             final File file = new File("test.raw");
             if (file.exists()) {
                 mRecorder.release();
             } else {
                 mRecorder.setOutputFile(file.getPath());
             }
 
             mRecorder.start();
             mRecorder.release();
             return true;
         }
         return super.onKeyDown(keyCode, event);
     }

ANDROID.UF.MEDIARECORDER is reported for the snippet on line 30 since there is an attempt to use the 'mRecorder' that is released if the output file exists (line 25).

Extension

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