Skip to content

Commit

Permalink
Safely release EncapsulatedPacket & add debug
Browse files Browse the repository at this point in the history
  • Loading branch information
Alemiz112 committed Aug 7, 2024
1 parent 7e85ea3 commit b7522a8
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import io.netty.buffer.ByteBufUtil;
import io.netty.buffer.CompositeByteBuf;
import io.netty.util.AbstractReferenceCounted;
import io.netty.util.ReferenceCountUtil;
import org.cloudburstmc.netty.channel.raknet.RakConstants;
import org.cloudburstmc.netty.channel.raknet.RakReliability;

Expand Down Expand Up @@ -123,7 +124,7 @@ public EncapsulatedPacket fromSplit(ByteBuf reassembled) {

@Override
protected void deallocate() {
this.buffer.release();
ReferenceCountUtil.release(this.buffer);
this.reliability = null;
this.reliabilityIndex = 0;
this.sequenceIndex = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
import io.netty.buffer.CompositeByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToMessageCodec;
import io.netty.util.internal.logging.InternalLogger;
import io.netty.util.internal.logging.InternalLoggerFactory;
import org.cloudburstmc.netty.channel.raknet.packet.EncapsulatedPacket;
import org.cloudburstmc.netty.channel.raknet.packet.RakDatagramPacket;

Expand All @@ -30,6 +32,8 @@
public class RakDatagramCodec extends MessageToMessageCodec<ByteBuf, RakDatagramPacket> {
public static final String NAME = "rak-datagram-codec";

private static final InternalLogger log = InternalLoggerFactory.getInstance(RakDatagramCodec.class);

public RakDatagramCodec() {
}

Expand Down Expand Up @@ -73,6 +77,9 @@ protected void decode(ChannelHandlerContext ctx, ByteBuf buffer, List<Object> li
try {
encapsulated.decode(buffer);
packet.getPackets().add(encapsulated.retain());
} catch (Throwable t) {
log.error("Error decoding encapsulated packet", t); // TODO: this is just temporary for debugging
throw t;
} finally {
encapsulated.release();
}
Expand Down

0 comments on commit b7522a8

Please sign in to comment.