From 7e3380db8b13d11b3b822494e563cce2122cd1a0 Mon Sep 17 00:00:00 2001 From: Hermet Park Date: Mon, 24 Apr 2023 17:18:32 +0900 Subject: [PATCH] sw_engine mempool: fixed to address a potential memory corruption issue. The previous memory pool was being shared by both the main and first threads, which could lead to corruption if any threading changes occurred. @Issue: https://github.com/thorvg/thorvg/issues/1370 --- src/lib/sw_engine/tvgSwMemPool.cpp | 8 ++++---- src/lib/tvgTaskScheduler.cpp | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/lib/sw_engine/tvgSwMemPool.cpp b/src/lib/sw_engine/tvgSwMemPool.cpp index a87b3fd1..05ff9ddf 100644 --- a/src/lib/sw_engine/tvgSwMemPool.cpp +++ b/src/lib/sw_engine/tvgSwMemPool.cpp @@ -60,16 +60,16 @@ void mpoolRetStrokeOutline(SwMpool* mpool, unsigned idx) SwMpool* mpoolInit(unsigned threads) { - if (threads == 0) threads = 1; + auto allocSize = threads + 1; auto mpool = static_cast(calloc(sizeof(SwMpool), 1)); - mpool->outline = static_cast(calloc(1, sizeof(SwOutline) * threads)); + mpool->outline = static_cast(calloc(1, sizeof(SwOutline) * allocSize)); if (!mpool->outline) goto err; - mpool->strokeOutline = static_cast(calloc(1, sizeof(SwOutline) * threads)); + mpool->strokeOutline = static_cast(calloc(1, sizeof(SwOutline) * allocSize)); if (!mpool->strokeOutline) goto err; - mpool->allocSize = threads; + mpool->allocSize = allocSize; return mpool; diff --git a/src/lib/tvgTaskScheduler.cpp b/src/lib/tvgTaskScheduler.cpp index 6b4b93c5..fcbcf207 100644 --- a/src/lib/tvgTaskScheduler.cpp +++ b/src/lib/tvgTaskScheduler.cpp @@ -135,7 +135,7 @@ struct TaskSchedulerImpl } if (!success && !taskQueues[i].pop(&task)) break; - (*task)(i); + (*task)(i + 1); } }