提交 6f254023 编写于 作者: I igerasim

8138819: (se) File descriptor leak when Selector.open fails

Reviewed-by: rriggs, alanb
上级 ea4e7475
/* /*
* Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2011, 2015, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -84,10 +84,24 @@ class KQueueSelectorImpl ...@@ -84,10 +84,24 @@ class KQueueSelectorImpl
long fds = IOUtil.makePipe(false); long fds = IOUtil.makePipe(false);
fd0 = (int)(fds >>> 32); fd0 = (int)(fds >>> 32);
fd1 = (int)fds; fd1 = (int)fds;
kqueueWrapper = new KQueueArrayWrapper(); try {
kqueueWrapper.initInterrupt(fd0, fd1); kqueueWrapper = new KQueueArrayWrapper();
fdMap = new HashMap<>(); kqueueWrapper.initInterrupt(fd0, fd1);
totalChannels = 1; fdMap = new HashMap<>();
totalChannels = 1;
} catch (Throwable t) {
try {
FileDispatcherImpl.closeIntFD(fd0);
} catch (IOException ioe0) {
t.addSuppressed(ioe0);
}
try {
FileDispatcherImpl.closeIntFD(fd1);
} catch (IOException ioe1) {
t.addSuppressed(ioe1);
}
throw t;
}
} }
......
/* /*
* Copyright (c) 2001, 2013, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2001, 2015, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -68,9 +68,23 @@ class DevPollSelectorImpl ...@@ -68,9 +68,23 @@ class DevPollSelectorImpl
long pipeFds = IOUtil.makePipe(false); long pipeFds = IOUtil.makePipe(false);
fd0 = (int) (pipeFds >>> 32); fd0 = (int) (pipeFds >>> 32);
fd1 = (int) pipeFds; fd1 = (int) pipeFds;
pollWrapper = new DevPollArrayWrapper(); try {
pollWrapper.initInterrupt(fd0, fd1); pollWrapper = new DevPollArrayWrapper();
fdToKey = new HashMap<Integer,SelectionKeyImpl>(); pollWrapper.initInterrupt(fd0, fd1);
fdToKey = new HashMap<>();
} catch (Throwable t) {
try {
FileDispatcherImpl.closeIntFD(fd0);
} catch (IOException ioe0) {
t.addSuppressed(ioe0);
}
try {
FileDispatcherImpl.closeIntFD(fd1);
} catch (IOException ioe1) {
t.addSuppressed(ioe1);
}
throw t;
}
} }
protected int doSelect(long timeout) protected int doSelect(long timeout)
......
/* /*
* Copyright (c) 2005, 2013, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2005, 2015, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -65,9 +65,23 @@ class EPollSelectorImpl ...@@ -65,9 +65,23 @@ class EPollSelectorImpl
long pipeFds = IOUtil.makePipe(false); long pipeFds = IOUtil.makePipe(false);
fd0 = (int) (pipeFds >>> 32); fd0 = (int) (pipeFds >>> 32);
fd1 = (int) pipeFds; fd1 = (int) pipeFds;
pollWrapper = new EPollArrayWrapper(); try {
pollWrapper.initInterrupt(fd0, fd1); pollWrapper = new EPollArrayWrapper();
fdToKey = new HashMap<>(); pollWrapper.initInterrupt(fd0, fd1);
fdToKey = new HashMap<>();
} catch (Throwable t) {
try {
FileDispatcherImpl.closeIntFD(fd0);
} catch (IOException ioe0) {
t.addSuppressed(ioe0);
}
try {
FileDispatcherImpl.closeIntFD(fd1);
} catch (IOException ioe1) {
t.addSuppressed(ioe1);
}
throw t;
}
} }
protected int doSelect(long timeout) throws IOException { protected int doSelect(long timeout) throws IOException {
......
/* /*
* Copyright (c) 2001, 2010, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2001, 2015, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -57,9 +57,23 @@ class PollSelectorImpl ...@@ -57,9 +57,23 @@ class PollSelectorImpl
long pipeFds = IOUtil.makePipe(false); long pipeFds = IOUtil.makePipe(false);
fd0 = (int) (pipeFds >>> 32); fd0 = (int) (pipeFds >>> 32);
fd1 = (int) pipeFds; fd1 = (int) pipeFds;
pollWrapper = new PollArrayWrapper(INIT_CAP); try {
pollWrapper.initInterrupt(fd0, fd1); pollWrapper = new PollArrayWrapper(INIT_CAP);
channelArray = new SelectionKeyImpl[INIT_CAP]; pollWrapper.initInterrupt(fd0, fd1);
channelArray = new SelectionKeyImpl[INIT_CAP];
} catch (Throwable t) {
try {
FileDispatcherImpl.closeIntFD(fd0);
} catch (IOException ioe0) {
t.addSuppressed(ioe0);
}
try {
FileDispatcherImpl.closeIntFD(fd1);
} catch (IOException ioe1) {
t.addSuppressed(ioe1);
}
throw t;
}
} }
protected int doSelect(long timeout) protected int doSelect(long timeout)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册