Skip to content

Commit a434f2c

Browse files
author
Nitesh Kant
committed
Fixes buffer management issue in ServerSentEventDecoder.
The lastEventType and lastEventId buffers were reused but not retained. This would make the buffers recycled after a generated ServerSentEvent (using these buffers) is released. This leads to all sort of issues, from illegal reference count to wrong dangling pointers. Now, retaining the buffers for lastEventId and lastEventType once (on channel remove or on receiving a new id/type) whenever they are used to create a ServerSentEvent instance. These buffers are released when the handler is removed.
1 parent 04ae32a commit a434f2c

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

rxnetty/src/main/java/io/reactivex/netty/protocol/http/sse/ServerSentEventDecoder.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,12 @@ protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) t
196196
switch (currentFieldType) {
197197
case Data:
198198
if (incompleteData.isReadable()) {
199+
if (null != lastEventId) {
200+
lastEventId.retain();
201+
}
202+
if (null != lastEventType) {
203+
lastEventType.retain();
204+
}
199205
out.add(ServerSentEvent.withEventIdAndType(lastEventId, lastEventType,
200206
incompleteData));
201207
} else {
@@ -207,6 +213,9 @@ protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) t
207213
lastEventId = incompleteData;
208214
} else {
209215
incompleteData.release();
216+
if (null != lastEventId) {
217+
lastEventId.release();
218+
}
210219
lastEventId = null;
211220
}
212221
break;
@@ -215,6 +224,9 @@ protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) t
215224
lastEventType = incompleteData;
216225
} else {
217226
incompleteData.release();
227+
if (null != lastEventType) {
228+
lastEventType.release();
229+
}
218230
lastEventType = null;
219231
}
220232
break;

0 commit comments

Comments
 (0)