From a9addae8236eebcbe2b764d045c2326ebecaa091 Mon Sep 17 00:00:00 2001 From: Damian Minkov Date: Fri, 18 Dec 2009 10:20:11 +0000 Subject: [PATCH] Fix length of newly created buffers in RawPacket. Fix NPE when we receive response for client transaction which has already expired. Lower the size of the newly created buffers used to receive udp packets. --- .../impl/neomedia/RTPConnectorInputStream.java | 10 ++++++++-- .../java/sip/communicator/impl/neomedia/RawPacket.java | 6 ++++-- .../impl/protocol/sip/SipStackSharing.java | 6 ++++++ 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/net/java/sip/communicator/impl/neomedia/RTPConnectorInputStream.java b/src/net/java/sip/communicator/impl/neomedia/RTPConnectorInputStream.java index f8f2f696b..917538c22 100755 --- a/src/net/java/sip/communicator/impl/neomedia/RTPConnectorInputStream.java +++ b/src/net/java/sip/communicator/impl/neomedia/RTPConnectorInputStream.java @@ -27,10 +27,15 @@ public class RTPConnectorInputStream */ private static final Object[] EMPTY_CONTROLS = new Object[0]; + /** + * The size of the buffers receiving packets coming from network. + */ + private static final int PACKET_RECEIVE_BUFFER = 4000; + /** * Packet receive buffer */ - private final byte[] buffer = new byte[65535]; + private final byte[] buffer = new byte[PACKET_RECEIVE_BUFFER]; /** * Whether this stream is closed. Used to control the termination of worker @@ -222,7 +227,8 @@ public void run() { while (!closed) { - DatagramPacket p = new DatagramPacket(buffer, 0, 65535); + DatagramPacket p = new DatagramPacket( + buffer, 0, PACKET_RECEIVE_BUFFER); try { diff --git a/src/net/java/sip/communicator/impl/neomedia/RawPacket.java b/src/net/java/sip/communicator/impl/neomedia/RawPacket.java index 7ec773f99..e13309003 100755 --- a/src/net/java/sip/communicator/impl/neomedia/RawPacket.java +++ b/src/net/java/sip/communicator/impl/neomedia/RawPacket.java @@ -330,7 +330,8 @@ public void setCsrcList(long[] newCsrcList) | newCsrcCount); this.buffer = newBuffer; - this.length = newBuffer.length - offset; + this.length = payloadOffsetForNewBuff + oldBuffer.length + - payloadOffsetForOldBuff - offset; } /** @@ -582,9 +583,10 @@ public void addExtension(byte[] extBuff, int newExtensionLen) //now copy the payload System.arraycopy(buffer, bufferOffset, newBuffer, newBufferOffset, getPayloadLength()); + newBufferOffset += getPayloadLength(); buffer = newBuffer; - this.length = newBuffLen - offset; + this.length = newBufferOffset - offset; } /** diff --git a/src/net/java/sip/communicator/impl/protocol/sip/SipStackSharing.java b/src/net/java/sip/communicator/impl/protocol/sip/SipStackSharing.java index 485c0609c..42415dfd4 100644 --- a/src/net/java/sip/communicator/impl/protocol/sip/SipStackSharing.java +++ b/src/net/java/sip/communicator/impl/protocol/sip/SipStackSharing.java @@ -656,6 +656,12 @@ public void processResponse(ResponseEvent event) + event.getResponse().getStatusCode() + " " + event.getResponse().getReasonPhrase()); + if(transaction == null) + { + logger.warn("Transaction is null, probably already expired!"); + return; + } + ProtocolProviderServiceSipImpl service = getServiceData(transaction); if (service != null)