From 5a29db7a9945c4cd095799451a6c563d5aeeed57 Mon Sep 17 00:00:00 2001 From: jan iversen Date: Wed, 4 Nov 2015 18:06:29 +0100 Subject: Solved CID 1326472, 1326473, 1326474 Coverity requires that allocated objects (use of new) are directly release, by foo = null; The gc will do this automatically at some point in time, so this will simply release the resource a bit earlier, which can save problems if the function is called in a tight loop. Updated to add close() before clearing the variable, this would normally be done by gc, but now a bit earlier. The assignment to null is not needed specifically, but Coverity calls it a leak if not assigned. Forgot .close(); Change-Id: Id273e7f36778c1691b260d28e741c6e32148c9d9 --- xmerge/source/bridge/java/XMergeBridge.java | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) (limited to 'xmerge/source') diff --git a/xmerge/source/bridge/java/XMergeBridge.java b/xmerge/source/bridge/java/XMergeBridge.java index 06d3b4b10564..5793f4fd78a6 100644 --- a/xmerge/source/bridge/java/XMergeBridge.java +++ b/xmerge/source/bridge/java/XMergeBridge.java @@ -437,6 +437,7 @@ public class XMergeBridge { docOut.write(fos); fos.flush(); fos.close(); + fos = null; i++; } @@ -446,6 +447,12 @@ public class XMergeBridge { ConverterInfoMgr.removeByJar(jarName); } catch (Exception ex1) { + /* Satisfy coverity */ + newxos.flush(); + newxos.close(); + newxos = null; + xis.close(); + xis = null; IOException ex2 = new IOException(); ex2.initCause(ex1); throw ex2; @@ -480,13 +487,24 @@ public class XMergeBridge { System.out.println("\nERROR : Stack Overflow. \n Increase of the JRE by adding the following line to the end of the javarc file \n \"-Xss1m\"\n"); } catch (Exception ex1) { + /* Satisfy coverity */ + newxos.flush(); + newxos.close(); + newxos = null; + xis.close(); + xis = null; IOException ex2 = new IOException(); ex2.initCause(ex1); throw ex2; } } - + /* Satisfy coverity */ + newxos.flush(); + newxos.close(); + newxos = null; + xis.close(); + xis = null; } private String getPath(URI uri){ -- cgit