aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar/protocol/MeiligaoProtocolDecoder.java
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2018-06-10 10:55:06 +1200
committerAnton Tananaev <anton.tananaev@gmail.com>2018-06-10 10:55:06 +1200
commit1dc1e06cfd4b7b23775984a254723b2d06b4f1dd (patch)
tree6dd89b120a7400ff3f08b2cb213cadc27112d0e7 /src/org/traccar/protocol/MeiligaoProtocolDecoder.java
parent58a222ba3d546dc2366586f2c904e70680a394bd (diff)
downloadtrackermap-server-1dc1e06cfd4b7b23775984a254723b2d06b4f1dd.tar.gz
trackermap-server-1dc1e06cfd4b7b23775984a254723b2d06b4f1dd.tar.bz2
trackermap-server-1dc1e06cfd4b7b23775984a254723b2d06b4f1dd.zip
Handle buffers reference count
Diffstat (limited to 'src/org/traccar/protocol/MeiligaoProtocolDecoder.java')
-rw-r--r--src/org/traccar/protocol/MeiligaoProtocolDecoder.java13
1 files changed, 9 insertions, 4 deletions
diff --git a/src/org/traccar/protocol/MeiligaoProtocolDecoder.java b/src/org/traccar/protocol/MeiligaoProtocolDecoder.java
index 738610cac..30905076e 100644
--- a/src/org/traccar/protocol/MeiligaoProtocolDecoder.java
+++ b/src/org/traccar/protocol/MeiligaoProtocolDecoder.java
@@ -189,7 +189,7 @@ public class MeiligaoProtocolDecoder extends BaseProtocolDecoder {
if (channel != null) {
ByteBuf buf = Unpooled.buffer(
- 2 + 2 + id.readableBytes() + 2 + msg.readableBytes() + 2 + 2); // TODO ref count
+ 2 + 2 + id.readableBytes() + 2 + msg.readableBytes() + 2 + 2);
buf.writeByte('@');
buf.writeByte('@');
@@ -197,6 +197,7 @@ public class MeiligaoProtocolDecoder extends BaseProtocolDecoder {
buf.writeBytes(id);
buf.writeShort(type);
buf.writeBytes(msg);
+ msg.release();
buf.writeShort(Checksum.crc16(Checksum.CRC16_CCITT_FALSE, buf.nioBuffer()));
buf.writeByte('\r');
buf.writeByte('\n');
@@ -415,7 +416,7 @@ public class MeiligaoProtocolDecoder extends BaseProtocolDecoder {
return null;
} else if (command == MSG_UPLOAD_PHOTO) {
byte imageIndex = buf.readByte();
- photos.put(imageIndex, Unpooled.buffer()); // TODO release photos
+ photos.put(imageIndex, Unpooled.buffer());
ByteBuf response = Unpooled.copiedBuffer(new byte[]{imageIndex});
sendResponse(channel, remoteAddress, id, MSG_UPLOAD_PHOTO_RESPONSE, response);
return null;
@@ -475,8 +476,12 @@ public class MeiligaoProtocolDecoder extends BaseProtocolDecoder {
byte imageIndex = buf.readByte();
buf.readUnsignedByte(); // image upload type
String uniqueId = Context.getIdentityManager().getById(deviceSession.getDeviceId()).getUniqueId();
- String file = Context.getMediaManager().writeFile(uniqueId, photos.remove(imageIndex), "jpg");
- position.set(Position.KEY_IMAGE, file);
+ ByteBuf photo = photos.remove(imageIndex);
+ try {
+ position.set(Position.KEY_IMAGE, Context.getMediaManager().writeFile(uniqueId, photo, "jpg"));
+ } finally {
+ photo.release();
+ }
}
String sentence = buf.toString(buf.readerIndex(), buf.readableBytes() - 4, StandardCharsets.US_ASCII);