You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@geode.apache.org by bs...@apache.org on 2019/04/17 19:21:35 UTC

[geode] branch develop updated: GEODE-6662 NioPlainEngine.ensureWrappedCapacity

This is an automated email from the ASF dual-hosted git repository.

bschuchardt pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/geode.git


The following commit(s) were added to refs/heads/develop by this push:
     new 064892c  GEODE-6662 NioPlainEngine.ensureWrappedCapacity
064892c is described below

commit 064892cc1ea60045fe43909eb9782a4b3fb314dd
Author: Bruce Schuchardt <bs...@pivotal.io>
AuthorDate: Wed Apr 17 12:17:36 2019 -0700

    GEODE-6662 NioPlainEngine.ensureWrappedCapacity
    
    Fixing a memory leak:
    
    Return the old buffer to the Buffers pool after copying its
    contents to a newly allocated buffer.
---
 .../src/main/java/org/apache/geode/internal/net/NioPlainEngine.java | 1 +
 .../test/java/org/apache/geode/internal/net/NioPlainEngineTest.java | 6 ++++--
 2 files changed, 5 insertions(+), 2 deletions(-)

diff --git a/geode-core/src/main/java/org/apache/geode/internal/net/NioPlainEngine.java b/geode-core/src/main/java/org/apache/geode/internal/net/NioPlainEngine.java
index 2c901e6..8a3e3fb 100644
--- a/geode-core/src/main/java/org/apache/geode/internal/net/NioPlainEngine.java
+++ b/geode-core/src/main/java/org/apache/geode/internal/net/NioPlainEngine.java
@@ -76,6 +76,7 @@ public class NioPlainEngine implements NioFilter {
       buffer = Buffers.acquireBuffer(bufferType, amount, stats);
       buffer.clear();
       buffer.put(oldBuffer);
+      Buffers.releaseBuffer(bufferType, oldBuffer, stats);
       lastReadPosition = buffer.position();
       lastProcessedPosition = 0;
     }
diff --git a/geode-core/src/test/java/org/apache/geode/internal/net/NioPlainEngineTest.java b/geode-core/src/test/java/org/apache/geode/internal/net/NioPlainEngineTest.java
index a7eb2d7..3406717 100644
--- a/geode-core/src/test/java/org/apache/geode/internal/net/NioPlainEngineTest.java
+++ b/geode-core/src/test/java/org/apache/geode/internal/net/NioPlainEngineTest.java
@@ -58,12 +58,14 @@ public class NioPlainEngineTest {
 
   @Test
   public void ensureWrappedCapacity() {
-    ByteBuffer wrappedBuffer = ByteBuffer.allocate(100);
+    ByteBuffer wrappedBuffer = Buffers.acquireReceiveBuffer(100, mockStats);
+    verify(mockStats, times(1)).incReceiverBufferSize(any(Integer.class), any(Boolean.class));
     wrappedBuffer.put(new byte[] {0, 1, 2, 3, 4, 5, 6, 7, 8, 9});
     nioEngine.lastReadPosition = 10;
     int requestedCapacity = 210;
     ByteBuffer result = nioEngine.ensureWrappedCapacity(requestedCapacity, wrappedBuffer,
-        Buffers.BufferType.UNTRACKED, mockStats);
+        Buffers.BufferType.TRACKED_RECEIVER, mockStats);
+    verify(mockStats, times(2)).incReceiverBufferSize(any(Integer.class), any(Boolean.class));
     assertThat(result.capacity()).isGreaterThanOrEqualTo(requestedCapacity);
     assertThat(result).isNotSameAs(wrappedBuffer);
     // make sure that data was transferred to the new buffer