[PATCH] cpupower: fix memory leak in print_{on,off}line_cpus()

Cryolitia PukNgae via B4 Relay posted 1 patch 1 month, 1 week ago
tools/power/cpupower/utils/helpers/misc.c | 4 ++++
1 file changed, 4 insertions(+)
[PATCH] cpupower: fix memory leak in print_{on,off}line_cpus()
Posted by Cryolitia PukNgae via B4 Relay 1 month, 1 week ago
From: Cryolitia PukNgae <cryolitia@uniontech.com>

{on,off}online_cpus_str not free after use

Suggested-by: Jun Zhan <zhanjun@uniontech.com>
Signed-off-by: Cryolitia PukNgae <cryolitia@uniontech.com>
---
 tools/power/cpupower/utils/helpers/misc.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/tools/power/cpupower/utils/helpers/misc.c b/tools/power/cpupower/utils/helpers/misc.c
index 166dc1e470ea6d70079fea6570750885d549603a..f3b4fe95520ff96a1be8b1ba8e7be1ec116b1bc0 100644
--- a/tools/power/cpupower/utils/helpers/misc.c
+++ b/tools/power/cpupower/utils/helpers/misc.c
@@ -213,6 +213,8 @@ void print_online_cpus(void)
 		bitmask_displaylist(online_cpus_str, str_len, online_cpus);
 		printf(_("Following CPUs are online:\n%s\n"), online_cpus_str);
 	}
+
+	free(online_cpus_str);
 }
 
 /* print_offline_cpus
@@ -232,6 +234,8 @@ void print_offline_cpus(void)
 		printf(_("Following CPUs are offline:\n%s\n"), offline_cpus_str);
 		printf(_("cpupower set operation was not performed on them\n"));
 	}
+
+	free(offline_cpus_str);
 }
 
 /*

---
base-commit: fab1beda7597fac1cecc01707d55eadb6bbe773c
change-id: 20250827-power-memoryleak-75c692220277

Best regards,
-- 
Cryolitia PukNgae <cryolitia@uniontech.com>
Re: [PATCH] cpupower: fix memory leak in print_{on,off}line_cpus()
Posted by Shuah Khan 2 weeks, 2 days ago
On 8/27/25 03:46, Cryolitia PukNgae via B4 Relay wrote:
> From: Cryolitia PukNgae <cryolitia@uniontech.com>
> 
> {on,off}online_cpus_str not free after use

How did you find this problem? The memory is released when cpupower
exits - do you need this free?

> 
> Suggested-by: Jun Zhan <zhanjun@uniontech.com>
> Signed-off-by: Cryolitia PukNgae <cryolitia@uniontech.com>
> ---
>   tools/power/cpupower/utils/helpers/misc.c | 4 ++++
>   1 file changed, 4 insertions(+)
> 
> diff --git a/tools/power/cpupower/utils/helpers/misc.c b/tools/power/cpupower/utils/helpers/misc.c
> index 166dc1e470ea6d70079fea6570750885d549603a..f3b4fe95520ff96a1be8b1ba8e7be1ec116b1bc0 100644
> --- a/tools/power/cpupower/utils/helpers/misc.c
> +++ b/tools/power/cpupower/utils/helpers/misc.c
> @@ -213,6 +213,8 @@ void print_online_cpus(void)
>   		bitmask_displaylist(online_cpus_str, str_len, online_cpus);
>   		printf(_("Following CPUs are online:\n%s\n"), online_cpus_str);
>   	}
> +
> +	free(online_cpus_str);
>   }
>   
>   /* print_offline_cpus
> @@ -232,6 +234,8 @@ void print_offline_cpus(void)
>   		printf(_("Following CPUs are offline:\n%s\n"), offline_cpus_str);
>   		printf(_("cpupower set operation was not performed on them\n"));
>   	}
> +
> +	free(offline_cpus_str);
>   }
>   
>   /*
> 

thanks,
-- Shuah