diff --git a/src/com/opera/core/systems/OperaWebElement.java b/src/com/opera/core/systems/OperaWebElement.java index 1cfee8ff8..88409a8d8 100644 --- a/src/com/opera/core/systems/OperaWebElement.java +++ b/src/com/opera/core/systems/OperaWebElement.java @@ -366,7 +366,7 @@ public String saveScreenshot(String filename, long timeout, boolean includeImage exec.screenWatcher(canvas, timeout, includeImage, hashes); if (includeImage && reply.getPng() != null) { - FileChannel stream; + FileChannel stream = null; try { stream = new FileOutputStream(filename).getChannel(); @@ -374,6 +374,14 @@ public String saveScreenshot(String filename, long timeout, boolean includeImage stream.close(); } catch (IOException e) { throw new WebDriverException("Failed to write file: " + e.getMessage(), e); + } finally { + if (stream != null) { + try { + stream.close(); + } catch (IOException e) { + throw new WebDriverException("Failed to close file channel stream: " + e.getMessage(), e); + } + } } }