From 1ebff2220dad220d74bcc93a6f3bd3618c95d87a Mon Sep 17 00:00:00 2001 From: David Rosca Date: Thu, 22 Aug 2024 09:29:21 +0200 Subject: [PATCH] frontends/va: Fix leaks with multiple coded buffer segments The buffers can be reused, so we must only allocate added segments and free unused segments. Fixes: be4287c3aa0 ("pipe: Extend get_feedback with additional metadata") Reviewed-By: Sil Vilerino Part-of: --- src/gallium/frontends/va/buffer.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/gallium/frontends/va/buffer.c b/src/gallium/frontends/va/buffer.c index c11cead3802..8626eaf2f42 100644 --- a/src/gallium/frontends/va/buffer.c +++ b/src/gallium/frontends/va/buffer.c @@ -216,11 +216,20 @@ VAStatus vlVaMapBuffer2(VADriverContextP ctx, VABufferID buf_id, *pbuff = buf->data; for (size_t i = 0; i < buf->extended_metadata.codec_unit_metadata_count - 1; i++) { - curr_buf_ptr->next = CALLOC(1, sizeof(VACodedBufferSegment)); + if (!curr_buf_ptr->next) + curr_buf_ptr->next = CALLOC(1, sizeof(VACodedBufferSegment)); if (!curr_buf_ptr->next) return VA_STATUS_ERROR_ALLOCATION_FAILED; curr_buf_ptr = curr_buf_ptr->next; } + if (curr_buf_ptr->next) { + VACodedBufferSegment *node = curr_buf_ptr->next; + while (node) { + VACodedBufferSegment *next = node->next; + FREE(node); + node = next; + } + } curr_buf_ptr->next = NULL; curr_buf_ptr = buf->data;