eolivelli commented on a change in pull request #276: Issue-271 
LedgerHandle#readEntries leaks ByteBufs
URL: https://github.com/apache/bookkeeper/pull/276#discussion_r129248134
 
 

 ##########
 File path: 
bookkeeper-server/src/main/java/org/apache/bookkeeper/client/LedgerEntry.java
 ##########
 @@ -53,22 +54,49 @@ public long getLength() {
         return length;
     }
 
+    /**
+     * Returns the content of the entry.
+     * This method can be called only once.
+     * While using v2 wire protocol this method will automatically release the 
internal ByteBuf
+     * @return
+     */
     public byte[] getEntry() {
+        if (data == null) {
+            throw new IllegalStateException("entry content can be accessed 
only once");
+        }
         byte[] entry = new byte[data.readableBytes()];
         data.readBytes(entry);
         data.release();
+        data = null;
         return entry;
     }
 
+    /**
+     * Returns the content of the entry.
+     * This method can be called only once.
+     * While using v2 wire protocol this method will automatically release the 
internal ByteBuf when calling the close
+     * method of the returned InputStream
+     *
+     * @return an InputStream which gives access to the content of the entry
+     */
     public InputStream getEntryInputStream() {
-        return new ByteBufInputStream(data);
+        if (data == null) {
 
 Review comment:
   same as above
 
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to