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 — IoUring: Fix buffer leak in DatagramChannel implementation when recv … · netty/netty@0dde641

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • transport-classes-io_uring/src/main/java/io/netty/channel/uring
    • IoUringDatagramChannel.java
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎transport-classes-io_uring/src/main/java/io/netty/channel/uring/IoUringDatagramChannel.java‎

Copy file name to clipboardExpand all lines: transport-classes-io_uring/src/main/java/io/netty/channel/uring/IoUringDatagramChannel.java
+20-24Lines changed: 20 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -346,37 +346,32 @@ protected void readComplete0(byte op, int res, int flags, short data, int outsta
346346
final ChannelPipeline pipeline = pipeline();
347347
ByteBuf byteBuf = this.readBuffer;
348348
assert byteBuf != null;
349+
MsgHdrMemory hdr = recvmsgHdrs.hdr(data);
350+
// Reset the id as this read was completed and so don't need to be cancelled later.
351+
recvmsgHdrs.setId(data, MsgHdrMemoryArray.NO_ID);
352+
349353
try {
350-
recvmsgComplete(pipeline, allocHandle, byteBuf, res, flags, data, outstanding);
354+
if (res < 0) {
355+
if (res != Native.ERRNO_ECANCELED_NEGATIVE) {
356+
// If res is negative we should pass it to ioResult(...) which will either throw
357+
// or convert it to 0 if we could not read because the socket was not readable.
358+
allocHandle.lastBytesRead(ioResult("io_uring recvmsg", res));
359+
}
360+
} else {
361+
allocHandle.lastBytesRead(res);
362+
if (hdr.hasPort(IoUringDatagramChannel.this)) {
363+
allocHandle.incMessagesRead(1);
364+
DatagramPacket packet = hdr.get(
365+
IoUringDatagramChannel.this, registration().attachment(), byteBuf, res);
366+
pipeline.fireChannelRead(packet);
367+
}
368+
}
351369
} catch (Throwable t) {
352370
Throwable e = (connected && t instanceof NativeIoException) ?
353371
translateForConnected((NativeIoException) t) : t;
354372
pipeline.fireExceptionCaught(e);
355373
}
356-
}
357374

358-
private void recvmsgComplete(ChannelPipeline pipeline, IoUringRecvByteAllocatorHandle allocHandle,
359-
ByteBuf byteBuf, int res, int flags, int idx, int outstanding)
360-
throws IOException {
361-
MsgHdrMemory hdr = recvmsgHdrs.hdr(idx);
362-
if (res < 0) {
363-
if (res != Native.ERRNO_ECANCELED_NEGATIVE) {
364-
// If res is negative we should pass it to ioResult(...) which will either throw
365-
// or convert it to 0 if we could not read because the socket was not readable.
366-
allocHandle.lastBytesRead(ioResult("io_uring recvmsg", res));
367-
}
368-
} else {
369-
allocHandle.lastBytesRead(res);
370-
if (hdr.hasPort(IoUringDatagramChannel.this)) {
371-
allocHandle.incMessagesRead(1);
372-
DatagramPacket packet = hdr.get(
373-
IoUringDatagramChannel.this, registration().attachment(), byteBuf, res);
374-
pipeline.fireChannelRead(packet);
375-
}
376-
}
377-
378-
// Reset the id as this read was completed and so don't need to be cancelled later.
379-
recvmsgHdrs.setId(idx, MsgHdrMemoryArray.NO_ID);
380375
if (outstanding == 0) {
381376
// There are no outstanding completion events, release the readBuffer and see if we need to schedule
382377
// another one or if the user will do it.
@@ -580,6 +575,7 @@ protected void unregistered() {
580575
super.unregistered();
581576
sendmsgHdrs.release();
582577
recvmsgHdrs.release();
578+
assert readBuffer == null;
583579
}
584580

585581
private static IOException translateForConnected(NativeIoException e) {

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.