From 9ce87aacd28e19c725d3cb3992845a6f437a1f0f Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Fri, 7 May 2021 09:58:10 +0200 Subject: [PATCH] module-profiler: avoid large stack alloc If the profiler manages to fill the complete buffer, we would have 8MB of data that we need to allocate on the stack. Don't do that and instead use a preallocated buffer large enough to copy things into. --- src/modules/module-profiler.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/modules/module-profiler.c b/src/modules/module-profiler.c index fdb04292b..37e89748a 100644 --- a/src/modules/module-profiler.c +++ b/src/modules/module-profiler.c @@ -80,6 +80,8 @@ struct impl { struct spa_ringbuffer buffer; uint8_t data[MAX_BUFFER]; + + uint8_t flush[MAX_BUFFER + sizeof(struct spa_pod_struct)]; }; struct resource_data { @@ -121,7 +123,7 @@ static void stop_flush(struct impl *impl) static void flush_timeout(void *data, uint64_t expirations) { struct impl *impl = data; - int32_t avail, size; + int32_t avail; uint32_t idx; struct spa_pod_struct *p; struct pw_resource *resource; @@ -137,8 +139,7 @@ static void flush_timeout(void *data, uint64_t expirations) } impl->empty = 0; - size = avail + sizeof(struct spa_pod_struct); - p = alloca(size); + p = (struct spa_pod_struct *)impl->flush; *p = SPA_POD_INIT_Struct(avail); spa_ringbuffer_read_data(&impl->buffer, impl->data, MAX_BUFFER,