Commit 26edd430 authored by wajahat.s@samsung.com's avatar wajahat.s@samsung.com

Close FileOutputStream in finally block in WebAppAuthenticator class method.

FileOutStream should be closed in finally block in writeKeyToFile() method,
as closing in try{} will not close and release system resources when an
exeption is thrown.

Also, catch relavant exception instead of catching generic exception.

BUG=None.

Review URL: https://codereview.chromium.org/405403002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@284735 0039d316-1c4b-4281-b951-d872f2087c98
parent fc8d6efc
......@@ -115,7 +115,7 @@ public class WebappAuthenticator {
if (input != null) {
input.close();
}
} catch (Exception e) {
} catch (IOException e) {
Log.e(TAG, "Could not close key input stream '" + file + "': " + e);
}
}
......@@ -124,6 +124,7 @@ public class WebappAuthenticator {
private static boolean writeKeyToFile(Context context, String basename, SecretKey key) {
File file = context.getFileStreamPath(basename);
byte[] keyBytes = key.getEncoded();
FileOutputStream output = null;
if (MAC_KEY_BYTE_COUNT != keyBytes.length) {
Log.e(TAG, "writeKeyToFile got key encoded bytes length " + keyBytes.length +
"; expected " + MAC_KEY_BYTE_COUNT);
......@@ -131,13 +132,20 @@ public class WebappAuthenticator {
}
try {
FileOutputStream output = new FileOutputStream(file);
output = new FileOutputStream(file);
output.write(keyBytes);
output.close();
return true;
} catch (Exception e) {
Log.e(TAG, "Could not write key to '" + file + "': " + e);
return false;
} finally {
try {
if (output != null) {
output.close();
}
} catch (IOException e) {
Log.e(TAG, "Could not close key output stream '" + file + "': " + e);
}
}
}
......
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