Skip to content

Commit

Permalink
Free a useless buffer.
Browse files Browse the repository at this point in the history
  • Loading branch information
elecharny committed Apr 18, 2024
1 parent 62643fe commit df98d09
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
Expand Up @@ -169,6 +169,12 @@ public void decode(IoSession session, IoBuffer in, ProtocolDecoderOutput out) th
buf = newBuf;

// Update the session attribute.
IoBuffer oldBuf = (IoBuffer) session.getAttribute(BUFFER);

if (oldBuf != null) {
oldBuf.free();
}

session.setAttribute(BUFFER, buf);
}
} else {
Expand Down Expand Up @@ -236,6 +242,7 @@ public void dispose(IoSession session) throws Exception {

private void removeSessionBuffer(IoSession session) {
IoBuffer buf = (IoBuffer) session.removeAttribute(BUFFER);

if (buf != null) {
buf.free();
}
Expand All @@ -247,6 +254,12 @@ private void storeRemainingInSession(IoBuffer buf, IoSession session) {
remainingBuf.order(buf.order());
remainingBuf.put(buf);

IoBuffer oldBuf = (IoBuffer) session.getAttribute(BUFFER);

if (oldBuf != null) {
oldBuf.free();
}

session.setAttribute(BUFFER, remainingBuf);
}

Expand Down
Expand Up @@ -273,6 +273,8 @@ public void messageReceived(final NextFilter nextFilter, final IoSession session
}
}
}

in.free();
}

/**
Expand Down

0 comments on commit df98d09

Please sign in to comment.