Return-Path: X-Original-To: apmail-camel-commits-archive@www.apache.org Delivered-To: apmail-camel-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 1FE9418F01 for ; Fri, 29 May 2015 15:06:53 +0000 (UTC) Received: (qmail 9720 invoked by uid 500); 29 May 2015 15:06:53 -0000 Delivered-To: apmail-camel-commits-archive@camel.apache.org Received: (qmail 9623 invoked by uid 500); 29 May 2015 15:06:53 -0000 Mailing-List: contact commits-help@camel.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@camel.apache.org Delivered-To: mailing list commits@camel.apache.org Received: (qmail 9478 invoked by uid 99); 29 May 2015 15:06:53 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 29 May 2015 15:06:52 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id D7D41E10DF; Fri, 29 May 2015 15:06:52 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: ningjiang@apache.org To: commits@camel.apache.org Date: Fri, 29 May 2015 15:06:54 -0000 Message-Id: <732ff1edc1c04649867927ffa9efb13d@git.apache.org> In-Reply-To: References: X-Mailer: ASF-Git Admin Mailer Subject: [3/4] camel git commit: CAMEL-8812 Fixed the Memory leak in HL7MLLPNettyDecoder with thanks to Gijsbert CAMEL-8812 Fixed the Memory leak in HL7MLLPNettyDecoder with thanks to Gijsbert Project: http://git-wip-us.apache.org/repos/asf/camel/repo Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/38a856d5 Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/38a856d5 Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/38a856d5 Branch: refs/heads/camel-2.15.x Commit: 38a856d53660c27986250f27baaca0b4c88961e2 Parents: c17f8c9 Author: Willem Jiang Authored: Fri May 29 22:23:00 2015 +0800 Committer: Willem Jiang Committed: Fri May 29 23:03:57 2015 +0800 ---------------------------------------------------------------------- .../camel/component/hl7/HL7MLLPNettyDecoder.java | 18 +++++++++++------- .../camel/component/hl7/HL7MLLPCodecTest.java | 2 +- 2 files changed, 12 insertions(+), 8 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/camel/blob/38a856d5/components/camel-hl7/src/main/java/org/apache/camel/component/hl7/HL7MLLPNettyDecoder.java ---------------------------------------------------------------------- diff --git a/components/camel-hl7/src/main/java/org/apache/camel/component/hl7/HL7MLLPNettyDecoder.java b/components/camel-hl7/src/main/java/org/apache/camel/component/hl7/HL7MLLPNettyDecoder.java index 4938cd5..9c04448 100644 --- a/components/camel-hl7/src/main/java/org/apache/camel/component/hl7/HL7MLLPNettyDecoder.java +++ b/components/camel-hl7/src/main/java/org/apache/camel/component/hl7/HL7MLLPNettyDecoder.java @@ -59,13 +59,17 @@ class HL7MLLPNettyDecoder extends DelimiterBasedFrameDecoder { protected Object decode(ChannelHandlerContext ctx, ByteBuf buffer) throws Exception { ByteBuf buf = (ByteBuf) super.decode(ctx, buffer); if (buf != null) { - int pos = buf.bytesBefore((byte) config.getStartByte()); - if (pos >= 0) { - ByteBuf msg = buf.readerIndex(pos + 1).slice(); - LOG.debug("Message ends with length {}", msg.readableBytes()); - return config.isProduceString() ? asString(msg) : asByteArray(msg); - } else { - throw new DecoderException("Did not find start byte " + (int) config.getStartByte()); + try { + int pos = buf.bytesBefore((byte) config.getStartByte()); + if (pos >= 0) { + ByteBuf msg = buf.readerIndex(pos + 1).slice(); + LOG.debug("Message ends with length {}", msg.readableBytes()); + return config.isProduceString() ? asString(msg) : asByteArray(msg); + } else { + throw new DecoderException("Did not find start byte " + (int) config.getStartByte()); + } + } finally { + buf.release(); } } // Message not complete yet - return null to be called again http://git-wip-us.apache.org/repos/asf/camel/blob/38a856d5/components/camel-hl7/src/test/java/org/apache/camel/component/hl7/HL7MLLPCodecTest.java ---------------------------------------------------------------------- diff --git a/components/camel-hl7/src/test/java/org/apache/camel/component/hl7/HL7MLLPCodecTest.java b/components/camel-hl7/src/test/java/org/apache/camel/component/hl7/HL7MLLPCodecTest.java index 1d9afef..96d6396 100644 --- a/components/camel-hl7/src/test/java/org/apache/camel/component/hl7/HL7MLLPCodecTest.java +++ b/components/camel-hl7/src/test/java/org/apache/camel/component/hl7/HL7MLLPCodecTest.java @@ -21,7 +21,6 @@ import ca.uhn.hl7v2.model.v24.message.ADR_A19; import ca.uhn.hl7v2.model.v24.segment.MSA; import ca.uhn.hl7v2.model.v24.segment.MSH; import ca.uhn.hl7v2.model.v24.segment.QRD; - import org.apache.camel.Exchange; import org.apache.camel.Processor; import org.apache.camel.builder.RouteBuilder; @@ -32,6 +31,7 @@ import org.junit.Test; * Unit test for the HL7MLLP Codec. */ public class HL7MLLPCodecTest extends HL7TestSupport { + protected JndiRegistry createRegistry() throws Exception { JndiRegistry jndi = super.createRegistry();