You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ofbiz.apache.org by mb...@apache.org on 2016/04/04 10:17:00 UTC

svn commit: r1737631 - /ofbiz/trunk/framework/common/src/org/ofbiz/common/CommonServices.java

Author: mbrohl
Date: Mon Apr  4 08:16:59 2016
New Revision: 1737631

URL: http://svn.apache.org/viewvc?rev=1737631&view=rev
Log:
Applied patch for OFBIZ-6972: Fix resource leaks in CommonServices.java.

File1 and file2 should be fixed by closing them in byteBufferTest. Taken from refactor todo list at https://cwiki.apache.org/confluence/display/OFBIZ/Re-Factor+To-Do+List .

Modified:
    ofbiz/trunk/framework/common/src/org/ofbiz/common/CommonServices.java

Modified: ofbiz/trunk/framework/common/src/org/ofbiz/common/CommonServices.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/common/src/org/ofbiz/common/CommonServices.java?rev=1737631&r1=1737630&r2=1737631&view=diff
==============================================================================
--- ofbiz/trunk/framework/common/src/org/ofbiz/common/CommonServices.java (original)
+++ ofbiz/trunk/framework/common/src/org/ofbiz/common/CommonServices.java Mon Apr  4 08:16:59 2016
@@ -363,16 +363,24 @@ public class CommonServices {
         String ofbizHome = System.getProperty("ofbiz.home");
         String outputPath1 = ofbizHome + (fileName1.startsWith("/") ? fileName1 : "/" + fileName1);
         String outputPath2 = ofbizHome + (fileName2.startsWith("/") ? fileName2 : "/" + fileName2);
-
+        RandomAccessFile file1 = null, file2 = null;
+        
         try {
-            RandomAccessFile file1 = new RandomAccessFile(outputPath1, "rw");
-            RandomAccessFile file2 = new RandomAccessFile(outputPath2, "rw");
+            file1 = new RandomAccessFile(outputPath1, "rw");
+            file2 = new RandomAccessFile(outputPath2, "rw");
             file1.write(buffer1.array());
             file2.write(buffer2.array());
         } catch (FileNotFoundException e) {
             Debug.logError(e, module);
         } catch (IOException e) {
             Debug.logError(e, module);
+        } finally {
+            try {
+                file1.close();
+                file2.close();
+            } catch (Exception e) {
+                Debug.logError(e, module);
+            }
         }
 
         return ServiceUtil.returnSuccess();