From 1e373664bd6748fe7902010c547425e04362bde5 Mon Sep 17 00:00:00 2001 From: Paul Gregoire Date: Thu, 22 Oct 2015 10:00:38 -0400 Subject: [PATCH] Fixed NPE in minaio handler that can occur on close/cleanup. Also fixed NPE on rtmp encode if null message is passed. --- .gitignore | 2 ++ .../server/net/rtmp/RTMPMinaIoHandler.java | 22 ++++++++++--------- .../net/rtmp/codec/RTMPProtocolEncoder.java | 17 ++++++++++---- 3 files changed, 27 insertions(+), 14 deletions(-) diff --git a/.gitignore b/.gitignore index 03dd4f98..b6668d8e 100644 --- a/.gitignore +++ b/.gitignore @@ -13,3 +13,5 @@ hs_err_pid* .settings target +log + diff --git a/src/main/java/org/red5/server/net/rtmp/RTMPMinaIoHandler.java b/src/main/java/org/red5/server/net/rtmp/RTMPMinaIoHandler.java index b06830db..5fb8e2f3 100644 --- a/src/main/java/org/red5/server/net/rtmp/RTMPMinaIoHandler.java +++ b/src/main/java/org/red5/server/net/rtmp/RTMPMinaIoHandler.java @@ -260,16 +260,18 @@ public void operationComplete(CloseFuture future) { future.removeListener(this); for (Object key : session.getAttributeKeys()) { Object obj = session.getAttribute(key); - log.debug("Attribute: {}", obj.getClass().getName()); - if (obj instanceof IoProcessor) { - log.debug("Flushing session in processor"); - ((IoProcessor) obj).flush(session); - log.debug("Removing session from processor"); - ((IoProcessor) obj).remove(session); - } else if (obj instanceof IoBuffer) { - log.debug("Clearing session buffer"); - ((IoBuffer) obj).clear(); - ((IoBuffer) obj).free(); + if (obj != null) { + log.debug("Attribute: {}", obj.getClass().getName()); + if (obj instanceof IoProcessor) { + log.debug("Flushing session in processor"); + ((IoProcessor) obj).flush(session); + log.debug("Removing session from processor"); + ((IoProcessor) obj).remove(session); + } else if (obj instanceof IoBuffer) { + log.debug("Clearing session buffer"); + ((IoBuffer) obj).clear(); + ((IoBuffer) obj).free(); + } } } } diff --git a/src/main/java/org/red5/server/net/rtmp/codec/RTMPProtocolEncoder.java b/src/main/java/org/red5/server/net/rtmp/codec/RTMPProtocolEncoder.java index a32f67ef..71ff9564 100755 --- a/src/main/java/org/red5/server/net/rtmp/codec/RTMPProtocolEncoder.java +++ b/src/main/java/org/red5/server/net/rtmp/codec/RTMPProtocolEncoder.java @@ -104,10 +104,19 @@ public class RTMPProtocolEncoder implements Constants, IEventEncoder { * @throws Exception Any decoding exception */ public IoBuffer encode(Object message) throws Exception { - try { - return encodePacket((Packet) message); - } catch (Exception e) { - log.error("Error encoding", e); + if (message != null) { + try { + return encodePacket((Packet) message); + } catch (Exception e) { + log.error("Error encoding", e); + } + } else if (log.isDebugEnabled()) { + try { + String callingMethod = Thread.currentThread().getStackTrace()[4].getMethodName(); + log.debug("Message is null at encode, expecting a Packet from: {}", callingMethod); + } catch (Throwable t) { + log.warn("Problem getting current calling method from stacktrace", t); + } } return null; }