7118373: (se) Potential leak file descriptor when deregistrating at around the same time as an async close
authorrobm
Tue, 17 Apr 2012 07:14:14 -0700
changeset 12440 2689ca179e22
parent 12439 07ab7fcb2f08
child 12441 dc1628ee8f30
child 12443 d7746e3cac0a
7118373: (se) Potential leak file descriptor when deregistrating at around the same time as an async close Reviewed-by: alanb
jdk/src/share/classes/sun/nio/ch/DatagramChannelImpl.java
jdk/src/share/classes/sun/nio/ch/ServerSocketChannelImpl.java
jdk/src/share/classes/sun/nio/ch/SocketChannelImpl.java
jdk/src/solaris/classes/sun/nio/ch/SinkChannelImpl.java
jdk/src/solaris/classes/sun/nio/ch/SourceChannelImpl.java
--- a/jdk/src/share/classes/sun/nio/ch/DatagramChannelImpl.java	Tue Apr 17 16:13:28 2012 +0400
+++ b/jdk/src/share/classes/sun/nio/ch/DatagramChannelImpl.java	Tue Apr 17 07:14:14 2012 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2001, 2011, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2001, 2012, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -970,7 +970,8 @@
 
     protected void implCloseSelectableChannel() throws IOException {
         synchronized (stateLock) {
-            nd.preClose(fd);
+            if (state != ST_KILLED)
+                nd.preClose(fd);
             ResourceManager.afterUdpClose();
 
             // if member of mulitcast group then invalidate all keys
--- a/jdk/src/share/classes/sun/nio/ch/ServerSocketChannelImpl.java	Tue Apr 17 16:13:28 2012 +0400
+++ b/jdk/src/share/classes/sun/nio/ch/ServerSocketChannelImpl.java	Tue Apr 17 07:14:14 2012 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2000, 2012, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -261,7 +261,8 @@
 
     protected void implCloseSelectableChannel() throws IOException {
         synchronized (stateLock) {
-            nd.preClose(fd);
+            if (state != ST_KILLED)
+                nd.preClose(fd);
             long th = thread;
             if (th != 0)
                 NativeThread.signal(th);
--- a/jdk/src/share/classes/sun/nio/ch/SocketChannelImpl.java	Tue Apr 17 16:13:28 2012 +0400
+++ b/jdk/src/share/classes/sun/nio/ch/SocketChannelImpl.java	Tue Apr 17 07:14:14 2012 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2000, 2012, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -816,7 +816,8 @@
             // channel from using the old fd, which might be recycled in the
             // meantime and allocated to an entirely different channel.
             //
-            nd.preClose(fd);
+            if (state != ST_KILLED)
+                nd.preClose(fd);
 
             // Signal native threads, if needed.  If a target thread is not
             // currently blocked in an I/O operation then no harm is done since
--- a/jdk/src/solaris/classes/sun/nio/ch/SinkChannelImpl.java	Tue Apr 17 16:13:28 2012 +0400
+++ b/jdk/src/solaris/classes/sun/nio/ch/SinkChannelImpl.java	Tue Apr 17 07:14:14 2012 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2000, 2009, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2000, 2012, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -84,7 +84,8 @@
 
     protected void implCloseSelectableChannel() throws IOException {
         synchronized (stateLock) {
-            nd.preClose(fd);
+            if (state != ST_KILLED)
+                nd.preClose(fd);
             long th = thread;
             if (th != 0)
                 NativeThread.signal(th);
--- a/jdk/src/solaris/classes/sun/nio/ch/SourceChannelImpl.java	Tue Apr 17 16:13:28 2012 +0400
+++ b/jdk/src/solaris/classes/sun/nio/ch/SourceChannelImpl.java	Tue Apr 17 07:14:14 2012 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2000, 2009, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2000, 2012, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -84,7 +84,8 @@
 
     protected void implCloseSelectableChannel() throws IOException {
         synchronized (stateLock) {
-            nd.preClose(fd);
+            if (state != ST_KILLED)
+                nd.preClose(fd);
             long th = thread;
             if (th != 0)
                 NativeThread.signal(th);