Properly cleanup ByteBuf in WirePacket (#487)

* Properly cleanup ByteBuf

* Release store ByteBuf also
This commit is contained in:
dextonanderson 2018-07-09 11:07:43 -05:00 committed by Dan Mulloy
parent 1d11908af1
commit aed2285bcb
2 changed files with 264 additions and 256 deletions

View File

@ -158,7 +158,7 @@ public class WirePacket {
* bytes from that packet
*
* @param packet Existing packet
* @return The ByteBuf
* @return the byte array
*/
public static byte[] bytesFromPacket(PacketContainer packet) {
checkNotNull(packet, "packet cannot be null!");
@ -177,6 +177,8 @@ public class WirePacket {
byte[] bytes = getBytes(buffer);
buffer.release();
// Rewrite them to the packet to avoid issues with certain packets
if (packet.getType() == PacketType.Play.Server.CUSTOM_PAYLOAD
|| packet.getType() == PacketType.Play.Client.CUSTOM_PAYLOAD) {
@ -195,6 +197,8 @@ public class WirePacket {
return ret;
}
store.release();
return bytes;
}
@ -220,7 +224,11 @@ public class WirePacket {
throw new RuntimeException("Failed to serialize packet contents.", ex);
}
return new WirePacket(id, getBytes(buffer));
byte[] bytes = getBytes(buffer);
buffer.release();
return new WirePacket(id, bytes);
}
public static void writeVarInt(ByteBuf output, int i) {