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();
// 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);
int adjustment = readerIndex - c.offset;
if (adjustment == c.length) {
// new slice would be empty, so remove instead
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.
updateComponentOffsets(0);