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 @@
package org.videolan.vlc;
import java.io.BufferedWriter;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
......@@ -79,18 +80,29 @@ public class VLCCrashHandler implements UncaughtExceptionHandler {
CharSequence timestamp = DateFormat.format("yyyyMMdd_kkmmss", System.currentTimeMillis());
String filename = name + "_" + timestamp + ".log";
FileOutputStream stream;
try {
FileOutputStream stream = new FileOutputStream(filename);
OutputStreamWriter output = new OutputStreamWriter(stream);
BufferedWriter bw = new BufferedWriter(output);
stream = new FileOutputStream(filename);
} catch (FileNotFoundException e) {
e.printStackTrace();
return;
}
OutputStreamWriter output = new OutputStreamWriter(stream);
BufferedWriter bw = new BufferedWriter(output);
try {
bw.write(log);
bw.newLine();
bw.close();
output.close();
} catch (IOException e) {
e.printStackTrace();
}finally {
try {
bw.close();
output.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
......
Markdown is supported
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