Skip to content

Commit

Permalink
Fixed NPE in minaio handler that can occur on close/cleanup. Also fix…
Browse files Browse the repository at this point in the history
…ed NPE on rtmp encode if null message is passed.
  • Loading branch information
mondain committed Oct 22, 2015
1 parent 2b3908f commit 1e37366
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 14 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,5 @@ hs_err_pid*
.settings
target

log

22 changes: 12 additions & 10 deletions src/main/java/org/red5/server/net/rtmp/RTMPMinaIoHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit 1e37366

Please sign in to comment.