Skip to content

Commit 6aee1d6

Browse files
committed
#3509 fix ByteBufInputStream memory leak
1 parent 6a8cb64 commit 6aee1d6

1 file changed

Lines changed: 8 additions & 3 deletions

File tree

src/main/scala/li/cil/oc/common/PacketHandler.scala

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,18 @@ abstract class PacketHandler {
2626
// Don't crash on badly formatted packets (may have been altered by a
2727
// malicious client, in which case we don't want to allow it to kill the
2828
// server like this). Just spam the log a bit... ;)
29+
var stream: InputStream = null
2930
try {
30-
val stream = new ByteBufInputStream(data)
31-
if (stream.read() == 0) dispatch(new PacketParser(stream, player))
32-
else dispatch(new PacketParser(new InflaterInputStream(stream), player))
31+
stream = new ByteBufInputStream(data)
32+
if (stream.read() != 0) stream = new InflaterInputStream(stream)
33+
dispatch(new PacketParser(stream, player))
3334
} catch {
3435
case e: Throwable =>
3536
OpenComputers.log.warn("Received a badly formatted packet.", e)
37+
} finally {
38+
if (stream != null) {
39+
stream.close()
40+
}
3641
}
3742

3843
// Avoid AFK kicks by marking players as non-idle when they send packets.

0 commit comments

Comments
 (0)