Commit 540cd2b7 authored by Gui-Dong Han's avatar Gui-Dong Han
Browse files

ktask: add memory leak handling for ktask_works in ktask_init()

BUAA inclusion
category: bugfix
bugzilla: https://gitee.com/openeuler/kernel/issues/I85XYV



-----------------------------------------------------

The pointer ktask_works is allocated using kmalloc_array,
but is not freed in the error handling code.
This can lead to a memory leak if the initialization process fails.
To address this issue,
the allocated memory for the pointer ktask_works
should be freed in the respective error handling code.

Signed-off-by: default avatarGui-Dong Han <hanguidong@buaa.edu.cn>
parent 9afce123
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -578,6 +578,7 @@ void __init ktask_init(void)
	ktask_wq = alloc_workqueue("ktask_wq", WQ_UNBOUND, 0);
	if (!ktask_wq) {
		pr_warn("disabled (failed to alloc ktask_wq)");
		kfree(ktask_works);
		goto out;
	}

@@ -629,6 +630,7 @@ void __init ktask_init(void)
		destroy_workqueue(ktask_wq);
	if (ktask_nonuma_wq)
		destroy_workqueue(ktask_nonuma_wq);
	kfree(ktask_works);
	ktask_wq = NULL;
	ktask_nonuma_wq = NULL;
}