uadk_engine/0077-uadk_engine-uask_async-fix-thread_attr-res-leak.patch
2023-11-29 16:35:32 +08:00

63 lines
2.0 KiB
Diff

From aaac36df78ea259008a2c3c11f9e766580d06367 Mon Sep 17 00:00:00 2001
From: Hao Fang <fanghao11@huawei.com>
Date: Sat, 25 Nov 2023 16:13:28 +0800
Subject: [PATCH 77/82] uadk_engine: uask_async: fix thread_attr res leak
When the pthread exit also need to call async_poll_task_free()
to unint thread_attr.
Signed-off-by: Hao Fang <fanghao11@huawei.com>
---
src/uadk_async.c | 8 ++++----
src/uadk_async.h | 1 +
2 files changed, 5 insertions(+), 4 deletions(-)
diff --git a/src/uadk_async.c b/src/uadk_async.c
index 342db2a..726ee09 100644
--- a/src/uadk_async.c
+++ b/src/uadk_async.c
@@ -132,6 +132,7 @@ void async_poll_task_free(void)
poll_queue.head = NULL;
pthread_mutex_unlock(&poll_queue.async_task_mutex);
+ pthread_attr_destroy(&poll_queue.thread_attr);
sem_destroy(&poll_queue.empty_sem);
sem_destroy(&poll_queue.full_sem);
pthread_mutex_destroy(&poll_queue.async_task_mutex);
@@ -359,7 +360,6 @@ static void *async_poll_process_func(void *args)
int async_module_init(void)
{
pthread_t thread_id;
- pthread_attr_t thread_attr;
memset(&poll_queue, 0, sizeof(struct async_poll_queue));
@@ -378,9 +378,9 @@ int async_module_init(void)
uadk_e_set_async_poll_state(ENABLE_ASYNC_POLLING);
- pthread_attr_init(&thread_attr);
- pthread_attr_setdetachstate(&thread_attr, PTHREAD_CREATE_DETACHED);
- if (pthread_create(&thread_id, &thread_attr, async_poll_process_func, NULL))
+ pthread_attr_init(&poll_queue.thread_attr);
+ pthread_attr_setdetachstate(&poll_queue.thread_attr, PTHREAD_CREATE_DETACHED);
+ if (pthread_create(&thread_id, &poll_queue.thread_attr, async_poll_process_func, NULL))
goto err;
poll_queue.thread_id = thread_id;
diff --git a/src/uadk_async.h b/src/uadk_async.h
index 678e392..6857927 100644
--- a/src/uadk_async.h
+++ b/src/uadk_async.h
@@ -69,6 +69,7 @@ struct async_poll_queue {
sem_t full_sem;
pthread_mutex_t async_task_mutex;
pthread_t thread_id;
+ pthread_attr_t thread_attr;
};
int async_setup_async_event_notification(struct async_op *op);
--
2.25.1