Skip to content

Commit

Permalink
Merge pull request #933 from JHOANG23/master
Browse files Browse the repository at this point in the history
Resource Leak Fix with try-with-resource block in readVersion()
  • Loading branch information
mrniko authored Jan 23, 2024
2 parents 1cec7b4 + 03c4672 commit 640617d
Showing 1 changed file with 3 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
import io.netty.util.concurrent.Future;
import io.netty.util.concurrent.GenericFutureListener;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.util.ArrayList;
import java.util.Enumeration;
Expand Down Expand Up @@ -94,8 +95,8 @@ public EncoderHandler(Configuration configuration, PacketEncoder encoder) throws
private void readVersion() throws IOException {
Enumeration<URL> resources = getClass().getClassLoader().getResources("META-INF/MANIFEST.MF");
while (resources.hasMoreElements()) {
try {
Manifest manifest = new Manifest(resources.nextElement().openStream());
try (InputStream inputStream = resources.nextElement().openStream()){
Manifest manifest = new Manifest(inputStream);
Attributes attrs = manifest.getMainAttributes();
if (attrs == null) {
continue;
Expand Down Expand Up @@ -174,7 +175,6 @@ private void sendMessage(HttpMessage msg, Channel channel, ByteBuf out, HttpResp

channel.writeAndFlush(LastHttpContent.EMPTY_LAST_CONTENT, promise).addListener(ChannelFutureListener.CLOSE);
}

private void sendError(HttpErrorMessage errorMsg, ChannelHandlerContext ctx, ChannelPromise promise) throws IOException {
final ByteBuf encBuf = encoder.allocateBuffer(ctx.alloc());
ByteBufOutputStream out = new ByteBufOutputStream(encBuf);
Expand Down

0 comments on commit 640617d

Please sign in to comment.