Prevent Unpooled.EMPTY_BUFFER from being stored in the composite buffer due to a zero length slice, which causes reference counting problems on subsequent discardReadBytes.

This commit is contained in:
John Fallows 2012-08-19 22:59:49 -07:00
parent 11c742f392
commit 83c21d70ee

View File

@ -1166,12 +1166,17 @@ public class DefaultCompositeByteBuf extends AbstractByteBuf implements Composit
} }
components.subList(0, firstComponentId).clear(); components.subList(0, firstComponentId).clear();
// Replace the first readable component with a new slice. // Remove or replace the first readable component with a new slice.
Component c = components.get(0); Component c = components.get(0);
int adjustment = readerIndex - c.offset; int adjustment = readerIndex - c.offset;
Component newC = new Component(c.buf.slice(adjustment, c.length - adjustment)); if (adjustment == c.length) {
c.buf.unsafe().release(); // new slice would be empty, so remove instead
components.set(0, newC); components.remove(0);
} else {
Component newC = new Component(c.buf.slice(adjustment, c.length - adjustment));
c.buf.unsafe().release();
components.set(0, newC);
}
// Update indexes and markers. // Update indexes and markers.
updateComponentOffsets(0); updateComponentOffsets(0);