From 635fbaaa4aa1fd27d89e4e7549f71c79fb8a47fb Mon Sep 17 00:00:00 2001 From: Amaury Denoyelle Date: Tue, 13 Aug 2024 11:08:08 +0200 Subject: [PATCH] MINOR: quic: allocate stream txbuf via qc_stream_desc API This commit simply adjusts QUIC stream buffer allocation. This operation is conducted by QUIC MUX using qc_stream_desc layer. Previously, qc_stream_buf_alloc() would return a qc_stream_buf instance and QUIC MUX would finalized the buffer area allocation. Change this to perform the buffer allocation directly into qc_stream_buf_alloc(). This patch clarifies the interaction between QUIC MUX and qc_stream_desc. It is cleaner to allocate the buffer via qc_stream_desc as it is already responsible to free the buffer. It also ensures that connection buffer accounting is only done after the whole qc_stream_buf and its buffer are allocated. Previously, the increment operation was performed between the two steps. This was not an issue, as this kind of error triggers the whole connection closure. However, if in the future this is handled as a stream closure instead, this commit ensures that the buffer remains valid in all cases. --- src/mux_quic.c | 6 ------ src/quic_stream.c | 8 ++++++-- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/mux_quic.c b/src/mux_quic.c index 8755f742a..30882ab2e 100644 --- a/src/mux_quic.c +++ b/src/mux_quic.c @@ -1037,12 +1037,6 @@ struct buffer *qcc_get_stream_txbuf(struct qcs *qcs, int *err) qcc->flags |= QC_CF_CONN_FULL; goto out; } - - if (!b_alloc(out, DB_MUX_TX)) { - TRACE_ERROR("buffer alloc failure", QMUX_EV_QCS_SEND, qcc->conn, qcs); - *err = 1; - goto out; - } } out: diff --git a/src/quic_stream.c b/src/quic_stream.c index 1d7a3c4de..a21391346 100644 --- a/src/quic_stream.c +++ b/src/quic_stream.c @@ -297,9 +297,13 @@ struct buffer *qc_stream_buf_alloc(struct qc_stream_desc *stream, if (!stream->buf) return NULL; - ++qc->stream_buf_count; + if (!b_alloc(&stream->buf->buf, DB_MUX_TX)) { + pool_free(pool_head_quic_stream_buf, stream->buf); + stream->buf = NULL; + return NULL; + } - stream->buf->buf = BUF_NULL; + ++qc->stream_buf_count; LIST_APPEND(&stream->buf_list, &stream->buf->list); return &stream->buf->buf;