From 556bf83c694c85c124b90428cb7622cc7babd411 Mon Sep 17 00:00:00 2001
From: Wenkai Lin <linwenkai6@hisilicon.com>
Date: Mon, 10 Jan 2022 18:52:02 +0800
Subject: [PATCH 38/53] uadk: env: bugfix for wd_init_resource

If sched is internal alloc, free it and set to NULL.
Otherwise do not free sched resource from user input.

Signed-off-by: Wenkai Lin <linwenkai6@hisilicon.com>
---
 wd_util.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/wd_util.c b/wd_util.c
index 9e96114..2e0e062 100644
--- a/wd_util.c
+++ b/wd_util.c
@@ -1412,7 +1412,10 @@ static int wd_init_resource(struct wd_env_config *config,
 err_uninit_alg:
 	ops->alg_uninit();
 err_uninit_sched:
-	wd_uninit_sched_config(config->sched);
+	if (config->internal_sched) {
+		wd_uninit_sched_config(config->sched);
+		config->sched = NULL;
+	}
 err_uninit_ctx:
 	wd_free_ctx(config->ctx_config);
 	return ret;
-- 
2.25.1

