aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar/ExtendedObjectDecoder.java
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2018-06-09 11:35:10 +1200
committerAnton Tananaev <anton.tananaev@gmail.com>2018-06-09 11:35:10 +1200
commit44cdc3449fccd22b21fec1c9a0febea807cc2489 (patch)
tree4807bb324ad9cde120e66168ddf8b020f80e3efd /src/org/traccar/ExtendedObjectDecoder.java
parentff1afd37323fa634315841cc84917700f969754b (diff)
downloadtrackermap-server-44cdc3449fccd22b21fec1c9a0febea807cc2489.tar.gz
trackermap-server-44cdc3449fccd22b21fec1c9a0febea807cc2489.tar.bz2
trackermap-server-44cdc3449fccd22b21fec1c9a0febea807cc2489.zip
Release incoming reference counted objects
Diffstat (limited to 'src/org/traccar/ExtendedObjectDecoder.java')
-rw-r--r--src/org/traccar/ExtendedObjectDecoder.java13
1 files changed, 8 insertions, 5 deletions
diff --git a/src/org/traccar/ExtendedObjectDecoder.java b/src/org/traccar/ExtendedObjectDecoder.java
index 22a9c7262..bb704c2e3 100644
--- a/src/org/traccar/ExtendedObjectDecoder.java
+++ b/src/org/traccar/ExtendedObjectDecoder.java
@@ -20,6 +20,7 @@ import io.netty.buffer.ByteBufUtil;
import io.netty.channel.Channel;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
+import io.netty.util.ReferenceCounted;
import org.traccar.helper.DataConverter;
import org.traccar.model.Position;
@@ -46,11 +47,9 @@ public abstract class ExtendedObjectDecoder extends ChannelInboundHandlerAdapter
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
NetworkMessage networkMessage = (NetworkMessage) msg;
Object originalMessage = networkMessage.getMessage();
- Object decodedMessage = decode(ctx.channel(), networkMessage.getRemoteAddress(), originalMessage);
- onMessageEvent(ctx.channel(), networkMessage.getRemoteAddress(), originalMessage, decodedMessage);
- if (originalMessage == decodedMessage) {
- ctx.fireChannelRead(originalMessage);
- } else {
+ try {
+ Object decodedMessage = decode(ctx.channel(), networkMessage.getRemoteAddress(), originalMessage);
+ onMessageEvent(ctx.channel(), networkMessage.getRemoteAddress(), originalMessage, decodedMessage);
if (decodedMessage == null) {
decodedMessage = handleEmptyMessage(ctx.channel(), networkMessage.getRemoteAddress(), originalMessage);
}
@@ -65,6 +64,10 @@ public abstract class ExtendedObjectDecoder extends ChannelInboundHandlerAdapter
ctx.fireChannelRead(decodedMessage);
}
}
+ } finally {
+ if (originalMessage instanceof ReferenceCounted) {
+ ((ReferenceCounted) originalMessage).release();
+ }
}
}