GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Fix a `Bytebuf` leak in `TcpDnsQueryDecoder` (#15033) · netty/netty@8d0d56b

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • codec-dns/src
    • main/java/io/netty/handler/codec/dns
      • TcpDnsQueryDecoder.java
    • test/java/io/netty/handler/codec/dns
      • TcpDnsTest.java
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎codec-dns/src/main/java/io/netty/handler/codec/dns/TcpDnsQueryDecoder.java‎

Copy file name to clipboardExpand all lines: codec-dns/src/main/java/io/netty/handler/codec/dns/TcpDnsQueryDecoder.java
+10-6Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,15 @@ protected Object decode(ChannelHandlerContext ctx, ByteBuf in) throws Exception
4545
return null;
4646
}
4747

48-
return DnsMessageUtil.decodeDnsQuery(decoder, frame.slice(), new DnsMessageUtil.DnsQueryFactory() {
49-
@Override
50-
public DnsQuery newQuery(int id, DnsOpCode dnsOpCode) {
51-
return new DefaultDnsQuery(id, dnsOpCode);
52-
}
53-
});
48+
try {
49+
return DnsMessageUtil.decodeDnsQuery(decoder, frame.slice(), new DnsMessageUtil.DnsQueryFactory() {
50+
@Override
51+
public DnsQuery newQuery(int id, DnsOpCode dnsOpCode) {
52+
return new DefaultDnsQuery(id, dnsOpCode);
53+
}
54+
});
55+
} finally {
56+
frame.release();
57+
}
5458
}
5559
}
Collapse file

‎codec-dns/src/test/java/io/netty/handler/codec/dns/TcpDnsTest.java‎

Copy file name to clipboardExpand all lines: codec-dns/src/test/java/io/netty/handler/codec/dns/TcpDnsTest.java
+20Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
*/
1616
package io.netty.handler.codec.dns;
1717

18+
import io.netty.buffer.ByteBuf;
1819
import io.netty.buffer.Unpooled;
1920
import io.netty.channel.embedded.EmbeddedChannel;
2021
import io.netty.util.ReferenceCountUtil;
@@ -48,6 +49,25 @@ public void testQueryDecode() {
4849
assertFalse(channel.finish());
4950
}
5051

52+
@Test
53+
public void testDecoderLeak() {
54+
EmbeddedChannel decoder = new EmbeddedChannel(new TcpDnsQueryDecoder());
55+
EmbeddedChannel encoder = new EmbeddedChannel(new TcpDnsQueryEncoder());
56+
int randomID = new Random().nextInt(60000 - 1000) + 1000;
57+
DnsQuery query = new DefaultDnsQuery(randomID, DnsOpCode.QUERY)
58+
.setRecord(DnsSection.QUESTION, new DefaultDnsQuestion(QUERY_DOMAIN, DnsRecordType.A));
59+
assertTrue(encoder.writeOutbound(query));
60+
final ByteBuf encoded = encoder.readOutbound();
61+
assertTrue(decoder.writeInbound(encoded));
62+
final DnsQuery decoded = decoder.readInbound();
63+
assertThat(decoded, is(query));
64+
// Make sure the ByteBuf is released by TcpDnsQueryDecoder
65+
assertTrue(encoded.refCnt() == 0);
66+
67+
assertFalse(encoder.finish());
68+
assertFalse(decoder.finish());
69+
}
70+
5171
@Test
5272
public void testResponseEncode() {
5373
EmbeddedChannel channel = new EmbeddedChannel(new TcpDnsResponseEncoder());

0 commit comments

Comments
0 (0)
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.