Fix #129: Memory leak when setOptions() fails while accepting a new connection
This commit is contained in:
parent
f779a4415c
commit
62446827df
src/main/java/io/netty/bootstrap
@ -209,7 +209,15 @@ public class ClientBootstrap extends Bootstrap {
|
||||
|
||||
// Set the options.
|
||||
Channel ch = getFactory().newChannel(pipeline);
|
||||
ch.getConfig().setOptions(getOptions());
|
||||
boolean success = false;
|
||||
try {
|
||||
ch.getConfig().setOptions(getOptions());
|
||||
success = true;
|
||||
} finally {
|
||||
if (!success) {
|
||||
ch.close();
|
||||
}
|
||||
}
|
||||
|
||||
// Bind.
|
||||
if (localAddress != null) {
|
||||
|
@ -183,8 +183,16 @@ public class ConnectionlessBootstrap extends Bootstrap {
|
||||
Channel ch = getFactory().newChannel(pipeline);
|
||||
|
||||
// Apply options.
|
||||
ch.getConfig().setPipelineFactory(getPipelineFactory());
|
||||
ch.getConfig().setOptions(getOptions());
|
||||
boolean success = false;
|
||||
try {
|
||||
ch.getConfig().setPipelineFactory(getPipelineFactory());
|
||||
ch.getConfig().setOptions(getOptions());
|
||||
success = true;
|
||||
} finally {
|
||||
if (!success) {
|
||||
ch.close();
|
||||
}
|
||||
}
|
||||
|
||||
// Bind
|
||||
ChannelFuture future = ch.bind(localAddress);
|
||||
@ -288,7 +296,16 @@ public class ConnectionlessBootstrap extends Bootstrap {
|
||||
|
||||
// Set the options.
|
||||
Channel ch = getFactory().newChannel(pipeline);
|
||||
ch.getConfig().setOptions(getOptions());
|
||||
boolean success = false;
|
||||
try {
|
||||
ch.getConfig().setPipelineFactory(getPipelineFactory());
|
||||
ch.getConfig().setOptions(getOptions());
|
||||
success = true;
|
||||
} finally {
|
||||
if (!success) {
|
||||
ch.close();
|
||||
}
|
||||
}
|
||||
|
||||
// Bind.
|
||||
if (localAddress != null) {
|
||||
|
@ -347,7 +347,11 @@ public class ServerBootstrap extends Bootstrap {
|
||||
ChannelHandlerContext ctx,
|
||||
ChildChannelStateEvent e) throws Exception {
|
||||
// Apply child options.
|
||||
e.getChildChannel().getConfig().setOptions(childOptions);
|
||||
try {
|
||||
e.getChildChannel().getConfig().setOptions(childOptions);
|
||||
} catch (Throwable t) {
|
||||
Channels.fireExceptionCaught(e.getChildChannel(), t);
|
||||
}
|
||||
ctx.sendUpstream(e);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user