Bug 1356693 - infer: fix RESOURCE_LEAK in webrtc
MozReview-Commit-ID: F3jc9X08MBD
--- a/media/webrtc/trunk/webrtc/modules/video_render/android/java/src/org/webrtc/videoengine/ViESurfaceRenderer.java
+++ b/media/webrtc/trunk/webrtc/modules/video_render/android/java/src/org/webrtc/videoengine/ViESurfaceRenderer.java
@@ -23,16 +23,17 @@ import android.graphics.Canvas;
import android.graphics.Rect;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import android.view.SurfaceHolder.Callback;
import android.util.Log;
import org.mozilla.gecko.annotation.WebRTCJNITarget;
+import org.mozilla.gecko.util.IOUtils;
public class ViESurfaceRenderer implements Callback {
private final static String TAG = "WEBRTC";
// the bitmap used for drawing.
private Bitmap bitmap = null;
private ByteBuffer byteBuffer = null;
@@ -148,26 +149,28 @@ public class ViESurfaceRenderer implemen
}
// It saves bitmap data to a JPEG picture, this function is for debug only.
@WebRTCJNITarget
private void saveBitmapToJPEG(int width, int height) {
ByteArrayOutputStream byteOutStream = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, byteOutStream);
+ FileOutputStream output = null;
try{
- FileOutputStream output = new FileOutputStream(String.format(
+ output = new FileOutputStream(String.format(
"/sdcard/render_%d.jpg", System.currentTimeMillis()));
output.write(byteOutStream.toByteArray());
output.flush();
output.close();
- }
- catch (FileNotFoundException e) {
- }
- catch (IOException e) {
+ } catch (IOException e) {
+ // This could be a FileNotFoundException if thrown by new FileOutputStream. Either way
+ // we don't seem to care
+ } finally {
+ IOUtils.safeStreamClose(output);
}
}
@WebRTCJNITarget
public void DrawByteBuffer() {
if(byteBuffer == null)
return;
byteBuffer.rewind();