GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — SPDY: Correctly release message once removed from internal storage · lltopk/netty@4ff0898

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • codec-http/src/main/java/io/netty/handler/codec/spdy
    • SpdyHttpDecoder.java
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎codec-http/src/main/java/io/netty/handler/codec/spdy/SpdyHttpDecoder.java‎

Copy file name to clipboardExpand all lines: codec-http/src/main/java/io/netty/handler/codec/spdy/SpdyHttpDecoder.java
+31-8Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -140,13 +140,13 @@ protected SpdyHttpDecoder(SpdyVersion version, int maxContentLength, Map<Integer
140140
}
141141

142142
@Override
143-
public void channelInactive(ChannelHandlerContext ctx) throws Exception {
143+
public void handlerRemoved(ChannelHandlerContext ctx) throws Exception {
144144
// Release any outstanding messages from the map
145145
for (Map.Entry<Integer, FullHttpMessage> entry : messageMap.entrySet()) {
146146
ReferenceCountUtil.safeRelease(entry.getValue());
147147
}
148148
messageMap.clear();
149-
super.channelInactive(ctx);
149+
super.handlerRemoved(ctx);
150150
}
151151

152152
protected FullHttpMessage putMessage(int streamId, FullHttpMessage message) {
@@ -271,21 +271,26 @@ protected void decode(ChannelHandlerContext ctx, SpdyFrame msg, List<Object> out
271271
return;
272272
}
273273

274+
FullHttpResponse httpResponseWithEntity = null;
274275
try {
275-
FullHttpResponse httpResponseWithEntity =
276-
createHttpResponse(spdySynReplyFrame, ctx.alloc());
276+
httpResponseWithEntity = createHttpResponse(spdySynReplyFrame, ctx.alloc());
277277

278278
// Set the Stream-ID as a header
279279
httpResponseWithEntity.headers().setInt(Names.STREAM_ID, streamId);
280280

281281
if (spdySynReplyFrame.isLast()) {
282282
HttpUtil.setContentLength(httpResponseWithEntity, 0);
283283
out.add(httpResponseWithEntity);
284+
httpResponseWithEntity = null;
284285
} else {
285286
// Response body will follow in a series of Data Frames
286287
putMessage(streamId, httpResponseWithEntity);
288+
httpResponseWithEntity = null;
287289
}
288290
} catch (Throwable t) {
291+
if (httpResponseWithEntity != null) {
292+
httpResponseWithEntity.release();
293+
}
289294
// If a client receives a SYN_REPLY without valid getStatus and version headers
290295
// the client must reply with a RST_STREAM frame indicating a PROTOCOL_ERROR
291296
SpdyRstStreamFrame spdyRstStreamFrame =
@@ -321,11 +326,16 @@ protected void decode(ChannelHandlerContext ctx, SpdyFrame msg, List<Object> out
321326
if (spdyHeadersFrame.isLast()) {
322327
HttpUtil.setContentLength(fullHttpMessage, 0);
323328
out.add(fullHttpMessage);
329+
fullHttpMessage = null;
324330
} else {
325331
// Response body will follow in a series of Data Frames
326332
putMessage(streamId, fullHttpMessage);
333+
fullHttpMessage = null;
327334
}
328335
} catch (Throwable t) {
336+
if (fullHttpMessage != null) {
337+
fullHttpMessage.release();
338+
}
329339
// If a client receives a SYN_REPLY without valid getStatus and version headers
330340
// the client must reply with a RST_STREAM frame indicating a PROTOCOL_ERROR
331341
SpdyRstStreamFrame spdyRstStreamFrame =
@@ -345,7 +355,10 @@ protected void decode(ChannelHandlerContext ctx, SpdyFrame msg, List<Object> out
345355

346356
if (spdyHeadersFrame.isLast()) {
347357
HttpUtil.setContentLength(fullHttpMessage, fullHttpMessage.content().readableBytes());
348-
removeMessage(streamId);
358+
FullHttpMessage removed = removeMessage(streamId);
359+
if (removed != null && removed != fullHttpMessage) {
360+
removed.release();
361+
}
349362
out.add(fullHttpMessage);
350363
}
351364

@@ -362,7 +375,11 @@ protected void decode(ChannelHandlerContext ctx, SpdyFrame msg, List<Object> out
362375

363376
ByteBuf content = fullHttpMessage.content();
364377
if (content.readableBytes() > maxContentLength - spdyDataFrame.content().readableBytes()) {
365-
removeMessage(streamId);
378+
FullHttpMessage removed = removeMessage(streamId);
379+
if (removed != null && removed != fullHttpMessage) {
380+
removed.release();
381+
}
382+
fullHttpMessage.release();
366383
throw new TooLongFrameException(
367384
"HTTP content length exceeded " + maxContentLength + " bytes: "
368385
+ spdyDataFrame.content().readableBytes());
@@ -374,15 +391,21 @@ protected void decode(ChannelHandlerContext ctx, SpdyFrame msg, List<Object> out
374391

375392
if (spdyDataFrame.isLast()) {
376393
HttpUtil.setContentLength(fullHttpMessage, content.readableBytes());
377-
removeMessage(streamId);
394+
FullHttpMessage removed = removeMessage(streamId);
395+
if (removed != null && removed != fullHttpMessage) {
396+
removed.release();
397+
}
378398
out.add(fullHttpMessage);
379399
}
380400

381401
} else if (msg instanceof SpdyRstStreamFrame) {
382402

383403
SpdyRstStreamFrame spdyRstStreamFrame = (SpdyRstStreamFrame) msg;
384404
int streamId = spdyRstStreamFrame.streamId();
385-
removeMessage(streamId);
405+
FullHttpMessage removed = removeMessage(streamId);
406+
if (removed != null) {
407+
removed.release();
408+
}
386409
}
387410
}
388411

0 commit comments

Comments
0 (0)
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.