[PATCH] cpupower: Fixing memory leaks

liujing posted 1 patch 2 days, 13 hours ago
[PATCH] cpupower: Fixing memory leaks
Posted by liujing 2 days, 13 hours ago
If execlp fails, page memory is not freed, so fix it.

Signed-off-by: liujing <liujing@cmss.chinamobile.com>

diff --git a/tools/power/cpupower/utils/cpupower.c b/tools/power/cpupower/utils/cpupower.c
index 9ec973165af1..36d486199630 100644
--- a/tools/power/cpupower/utils/cpupower.c
+++ b/tools/power/cpupower/utils/cpupower.c
@@ -98,7 +98,7 @@ static int print_man_page(const char *subpage)
 	}
 
 	execlp("man", "man", page, NULL);
-
+	free(page);
 	/* should not be reached */
 	return -EINVAL;
 }
-- 
2.27.0
Re: [PATCH] cpupower: Fixing memory leaks
Posted by Shuah Khan 1 day, 8 hours ago
On 11/21/24 06:32, liujing wrote:
> If execlp fails, page memory is not freed, so fix it.

How did you find the problem?

> 
> Signed-off-by: liujing <liujing@cmss.chinamobile.com>
> 
> diff --git a/tools/power/cpupower/utils/cpupower.c b/tools/power/cpupower/utils/cpupower.c
> index 9ec973165af1..36d486199630 100644
> --- a/tools/power/cpupower/utils/cpupower.c
> +++ b/tools/power/cpupower/utils/cpupower.c
> @@ -98,7 +98,7 @@ static int print_man_page(const char *subpage)
>   	}
>   
>   	execlp("man", "man", page, NULL);
> -
> +	free(page);

The memory gets free'ed when process exits. Why do you need this?
  
  
>   	/* should not be reached */
>   	return -EINVAL;
>   }

thanks,
-- Shuah