From b82160c2e71648b1bfc2be1991aeb1ef1e37a716 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Barnab=C3=A1s=20P=C5=91cze?= Date: Wed, 13 Aug 2025 15:37:51 +0200 Subject: [PATCH] spa: libcamera: source: remove stale data from buffers When clearing the buffers, remove the stale pointers and file descriptors as accidental reuse of those is problematic and potentially difficult to diagnose. Do this for every data plane. Also clear the node's `buffer` structures to remove any references to the provided `spa_buffer` objects and related metadata. --- spa/plugins/libcamera/libcamera-source.cpp | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/spa/plugins/libcamera/libcamera-source.cpp b/spa/plugins/libcamera/libcamera-source.cpp index 18cca35ea..a469ed377 100644 --- a/spa/plugins/libcamera/libcamera-source.cpp +++ b/spa/plugins/libcamera/libcamera-source.cpp @@ -374,13 +374,18 @@ err: int spa_libcamera_clear_buffers(struct port *port) { for (std::size_t i = 0; i < port->n_buffers; i++) { - struct buffer *b; - struct spa_data *d; + buffer *b = &port->buffers[i]; + spa_buffer *sb = b->outbuf; - b = &port->buffers[i]; - d = b->outbuf->datas; + for (std::size_t j = 0; j < sb->n_datas; j++) { + auto *d = &sb->datas[j]; - d[0].type = SPA_ID_INVALID; + d->type = SPA_ID_INVALID; + d->data = nullptr; + d->fd = -1; + } + + *b = {}; } port->n_buffers = 0;