Commit c4908ae7 authored by zhujiashun's avatar zhujiashun

fix a leak when sending h2 req

parent ae0df7fe
......@@ -1522,18 +1522,9 @@ H2UnsentRequest::AppendAndDestroySelf(butil::IOBuf* out, Socket* socket) {
<< " h2req=" << (StreamUserData*)this;
return butil::Status(EH2RUNOUTSTREAMS, "Fail to allocate stream_id");
}
H2StreamContext* sctx = _sctx.release();
sctx->Init(ctx, id);
const int rc = ctx->TryToInsertStream(id, sctx);
if (rc < 0) {
delete sctx;
return butil::Status(EINTERNAL, "Fail to insert existing stream_id");
} else if (rc > 0) {
delete sctx;
return butil::Status(ELOGOFF, "the connection just issued GOAWAY");
}
_stream_id = sctx->stream_id();
std::unique_ptr<H2StreamContext> sctx(std::move(_sctx));
sctx->Init(ctx, id);
// flow control
if (!_cntl->request_attachment().empty()) {
const int64_t data_size = _cntl->request_attachment().size();
......@@ -1542,6 +1533,16 @@ H2UnsentRequest::AppendAndDestroySelf(butil::IOBuf* out, Socket* socket) {
}
}
const int rc = ctx->TryToInsertStream(id, sctx.get());
if (rc < 0) {
return butil::Status(EINTERNAL, "Fail to insert existing stream_id");
} else if (rc > 0) {
return butil::Status(ELOGOFF, "the connection just issued GOAWAY");
}
_stream_id = sctx->stream_id();
// After calling TryToInsertStream, ownership of sctx is transferred to ctx
sctx.release();
HPacker& hpacker = ctx->hpacker();
butil::IOBufAppender appender;
HPackOptions options;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment