zookeeper-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From f..@apache.org
Subject svn commit: r1642440 - in /zookeeper/branches/branch-3.5: ./ src/contrib/loggraph/src/java/org/apache/zookeeper/graph/ src/contrib/loggraph/src/java/org/apache/zookeeper/graph/servlets/ src/contrib/rest/src/java/org/apache/zookeeper/server/jersey/cfg/ ...
Date Sat, 29 Nov 2014 15:54:58 GMT
Author: fpj
Date: Sat Nov 29 15:54:58 2014
New Revision: 1642440

URL: http://svn.apache.org/r1642440
Log:
ZOOKEEPER-2064 Prevent resource leak in various classes (Ted Yu via fpj)


Modified:
    zookeeper/branches/branch-3.5/CHANGES.txt
    zookeeper/branches/branch-3.5/src/contrib/loggraph/src/java/org/apache/zookeeper/graph/Log4JSource.java
    zookeeper/branches/branch-3.5/src/contrib/loggraph/src/java/org/apache/zookeeper/graph/RandomAccessFileReader.java
    zookeeper/branches/branch-3.5/src/contrib/loggraph/src/java/org/apache/zookeeper/graph/servlets/NumEvents.java
    zookeeper/branches/branch-3.5/src/contrib/loggraph/src/java/org/apache/zookeeper/graph/servlets/StaticContent.java
    zookeeper/branches/branch-3.5/src/contrib/rest/src/java/org/apache/zookeeper/server/jersey/cfg/RestCfg.java
    zookeeper/branches/branch-3.5/src/java/systest/org/apache/zookeeper/test/system/GenerateLoad.java
    zookeeper/branches/branch-3.5/src/java/systest/org/apache/zookeeper/test/system/QuorumPeerInstance.java

Modified: zookeeper/branches/branch-3.5/CHANGES.txt
URL: http://svn.apache.org/viewvc/zookeeper/branches/branch-3.5/CHANGES.txt?rev=1642440&r1=1642439&r2=1642440&view=diff
==============================================================================
--- zookeeper/branches/branch-3.5/CHANGES.txt (original)
+++ zookeeper/branches/branch-3.5/CHANGES.txt Sat Nov 29 15:54:58 2014
@@ -15,6 +15,8 @@ BUGFIXES:
  
   ZOOKEEPER-2060 Trace bug in NettyServerCnxnFactory (Ian via fpj)
 
+  ZOOKEEPER-2064 Prevent resource leak in various classes (Ted Yu via fpj)
+
 IMPROVEMENTS:
   ZOOKEEPER-1660 Documentation for Dynamic Reconfiguration (Reed Wanderman-Milne via shralex)
 

Modified: zookeeper/branches/branch-3.5/src/contrib/loggraph/src/java/org/apache/zookeeper/graph/Log4JSource.java
URL: http://svn.apache.org/viewvc/zookeeper/branches/branch-3.5/src/contrib/loggraph/src/java/org/apache/zookeeper/graph/Log4JSource.java?rev=1642440&r1=1642439&r2=1642440&view=diff
==============================================================================
--- zookeeper/branches/branch-3.5/src/contrib/loggraph/src/java/org/apache/zookeeper/graph/Log4JSource.java
(original)
+++ zookeeper/branches/branch-3.5/src/contrib/loggraph/src/java/org/apache/zookeeper/graph/Log4JSource.java
Sat Nov 29 15:54:58 2014
@@ -351,11 +351,21 @@ public class Log4JSource implements LogS
 		
 		LogIterator iter = s.iterator(starttime, endtime);
 		System.out.println(iter);
+		try {
+		  iter.close();
+		} catch (IOException ioe) {
+		  System.out.println(ioe.getMessage());
+		}
 	    }; };
 	    Thread t2 = new Thread() { public void run () { 
 		
 		LogIterator iter = s.iterator(starttime, endtime);
 		System.out.println(iter);
+		try {
+		  iter.close();
+		} catch (IOException ioe) {
+		  System.out.println(ioe.getMessage());
+		}
 	    }; };
 	    Thread t3 = new Thread() { public void run () { 
 		

Modified: zookeeper/branches/branch-3.5/src/contrib/loggraph/src/java/org/apache/zookeeper/graph/RandomAccessFileReader.java
URL: http://svn.apache.org/viewvc/zookeeper/branches/branch-3.5/src/contrib/loggraph/src/java/org/apache/zookeeper/graph/RandomAccessFileReader.java?rev=1642440&r1=1642439&r2=1642440&view=diff
==============================================================================
--- zookeeper/branches/branch-3.5/src/contrib/loggraph/src/java/org/apache/zookeeper/graph/RandomAccessFileReader.java
(original)
+++ zookeeper/branches/branch-3.5/src/contrib/loggraph/src/java/org/apache/zookeeper/graph/RandomAccessFileReader.java
Sat Nov 29 15:54:58 2014
@@ -324,5 +324,6 @@ public class RandomAccessFileReader exte
 	System.out.println(f.readLine());
 	f.seek(pos2);
 	System.out.println(f.readLine());
+	f.close();
     }
 };

Modified: zookeeper/branches/branch-3.5/src/contrib/loggraph/src/java/org/apache/zookeeper/graph/servlets/NumEvents.java
URL: http://svn.apache.org/viewvc/zookeeper/branches/branch-3.5/src/contrib/loggraph/src/java/org/apache/zookeeper/graph/servlets/NumEvents.java?rev=1642440&r1=1642439&r2=1642440&view=diff
==============================================================================
--- zookeeper/branches/branch-3.5/src/contrib/loggraph/src/java/org/apache/zookeeper/graph/servlets/NumEvents.java
(original)
+++ zookeeper/branches/branch-3.5/src/contrib/loggraph/src/java/org/apache/zookeeper/graph/servlets/NumEvents.java
Sat Nov 29 15:54:58 2014
@@ -81,6 +81,7 @@ public class NumEvents extends JsonServl
 	if (LOG.isDebugEnabled()) {
 	    LOG.debug("handle(start= " + starttime + ", end=" + endtime + ", numEntries=" + size
+")");
 	}
+	iter.close();
 	return JSONValue.toJSONString(data);
     }
 }

Modified: zookeeper/branches/branch-3.5/src/contrib/loggraph/src/java/org/apache/zookeeper/graph/servlets/StaticContent.java
URL: http://svn.apache.org/viewvc/zookeeper/branches/branch-3.5/src/contrib/loggraph/src/java/org/apache/zookeeper/graph/servlets/StaticContent.java?rev=1642440&r1=1642439&r2=1642440&view=diff
==============================================================================
--- zookeeper/branches/branch-3.5/src/contrib/loggraph/src/java/org/apache/zookeeper/graph/servlets/StaticContent.java
(original)
+++ zookeeper/branches/branch-3.5/src/contrib/loggraph/src/java/org/apache/zookeeper/graph/servlets/StaticContent.java
Sat Nov 29 15:54:58 2014
@@ -39,9 +39,12 @@ public class StaticContent extends HttpS
 	    response.setStatus(HttpServletResponse.SC_NOT_FOUND);
 	    return;
 	}
-	
-	while (resource.available() > 0) {
+	try {
+	  while (resource.available() > 0) {
 	    response.getWriter().write(resource.read());
+	  }
+	} finally {
+	  resource.close();
 	}
 	//        response.setContentType("text/plain;charset=utf-8");
         response.setStatus(HttpServletResponse.SC_OK);

Modified: zookeeper/branches/branch-3.5/src/contrib/rest/src/java/org/apache/zookeeper/server/jersey/cfg/RestCfg.java
URL: http://svn.apache.org/viewvc/zookeeper/branches/branch-3.5/src/contrib/rest/src/java/org/apache/zookeeper/server/jersey/cfg/RestCfg.java?rev=1642440&r1=1642439&r2=1642440&view=diff
==============================================================================
--- zookeeper/branches/branch-3.5/src/contrib/rest/src/java/org/apache/zookeeper/server/jersey/cfg/RestCfg.java
(original)
+++ zookeeper/branches/branch-3.5/src/contrib/rest/src/java/org/apache/zookeeper/server/jersey/cfg/RestCfg.java
Sat Nov 29 15:54:58 2014
@@ -36,9 +36,13 @@ public class RestCfg {
    }
 
    public RestCfg(InputStream io) throws IOException {
+     try {
        cfg.load(io);
        extractEndpoints();
        extractCredentials();
+     } finally {
+       io.close();
+     }
    }
 
    private void extractCredentials() {

Modified: zookeeper/branches/branch-3.5/src/java/systest/org/apache/zookeeper/test/system/GenerateLoad.java
URL: http://svn.apache.org/viewvc/zookeeper/branches/branch-3.5/src/java/systest/org/apache/zookeeper/test/system/GenerateLoad.java?rev=1642440&r1=1642439&r2=1642440&view=diff
==============================================================================
--- zookeeper/branches/branch-3.5/src/java/systest/org/apache/zookeeper/test/system/GenerateLoad.java
(original)
+++ zookeeper/branches/branch-3.5/src/java/systest/org/apache/zookeeper/test/system/GenerateLoad.java
Sat Nov 29 15:54:58 2014
@@ -696,12 +696,16 @@ public class GenerateLoad {
         s.getOutputStream().write("stat".getBytes());
         BufferedReader br = new BufferedReader(new InputStreamReader(s.getInputStream()));
         String line;
-        while((line = br.readLine()) != null) {
+        try {
+          while((line = br.readLine()) != null) {
             if (line.startsWith("Mode: ")) {
-                return line.substring(6);
+              return line.substring(6);
             }
+          }
+          return "unknown";
+        } finally {
+          s.close();
         }
-        return "unknown";
     }
 
     private static void doUsage() {

Modified: zookeeper/branches/branch-3.5/src/java/systest/org/apache/zookeeper/test/system/QuorumPeerInstance.java
URL: http://svn.apache.org/viewvc/zookeeper/branches/branch-3.5/src/java/systest/org/apache/zookeeper/test/system/QuorumPeerInstance.java?rev=1642440&r1=1642439&r2=1642440&view=diff
==============================================================================
--- zookeeper/branches/branch-3.5/src/java/systest/org/apache/zookeeper/test/system/QuorumPeerInstance.java
(original)
+++ zookeeper/branches/branch-3.5/src/java/systest/org/apache/zookeeper/test/system/QuorumPeerInstance.java
Sat Nov 29 15:54:58 2014
@@ -68,7 +68,12 @@ class QuorumPeerInstance implements Inst
             Properties p;
             if (zkDirs.exists()) {
                 p = new Properties();
-                p.load(new FileInputStream(zkDirs));
+                FileInputStream input = new FileInputStream(zkDirs);
+                try {
+                  p.load(input);
+                } finally {
+                  input.close();
+                }
             } else {
                 p = System.getProperties();
             }



Mime
View raw message