Commit f1069517 authored by Jean-Baptiste Kempf's avatar Jean-Baptiste Kempf
Browse files

VLCCrashHandler: do not leak resources

And yes, the try{} catch in the finally is necessary, because .close()
can resend an IOException.
parent 8eb52cba
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
package org.videolan.vlc; package org.videolan.vlc;
import java.io.BufferedWriter; import java.io.BufferedWriter;
import java.io.FileNotFoundException;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.OutputStreamWriter; import java.io.OutputStreamWriter;
...@@ -79,20 +80,31 @@ public class VLCCrashHandler implements UncaughtExceptionHandler { ...@@ -79,20 +80,31 @@ public class VLCCrashHandler implements UncaughtExceptionHandler {
CharSequence timestamp = DateFormat.format("yyyyMMdd_kkmmss", System.currentTimeMillis()); CharSequence timestamp = DateFormat.format("yyyyMMdd_kkmmss", System.currentTimeMillis());
String filename = name + "_" + timestamp + ".log"; String filename = name + "_" + timestamp + ".log";
FileOutputStream stream;
try { try {
FileOutputStream stream = new FileOutputStream(filename); stream = new FileOutputStream(filename);
} catch (FileNotFoundException e) {
e.printStackTrace();
return;
}
OutputStreamWriter output = new OutputStreamWriter(stream); OutputStreamWriter output = new OutputStreamWriter(stream);
BufferedWriter bw = new BufferedWriter(output); BufferedWriter bw = new BufferedWriter(output);
try {
bw.write(log); bw.write(log);
bw.newLine(); bw.newLine();
} catch (IOException e) {
e.printStackTrace();
}finally {
try {
bw.close(); bw.close();
output.close(); output.close();
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} }
} }
}
private void writeLogcat(String name) { private void writeLogcat(String name) {
CharSequence timestamp = DateFormat.format("yyyyMMdd_kkmmss", System.currentTimeMillis()); CharSequence timestamp = DateFormat.format("yyyyMMdd_kkmmss", System.currentTimeMillis());
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment