linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] perf kmem: Fix memory leak in compact_gfp_flags()
@ 2019-10-16 13:26 Yunfeng Ye
  2019-10-16 14:06 ` Arnaldo Carvalho de Melo
  0 siblings, 1 reply; 3+ messages in thread
From: Yunfeng Ye @ 2019-10-16 13:26 UTC (permalink / raw)
  To: peterz, mingo, acme, mark.rutland, alexander.shishkin, jolsa, namhyung
  Cc: linux-kernel, hushiyuan, linfeilong

The memory @orig_flags is allocated by strdup(), it is freed on the
normal path, but leak to free on the error path.

Fix this by adding free(orig_flags) on the error path.

Fixes: 0e11115644b3 ("perf kmem: Print gfp flags in human readable string")
Signed-off-by: Yunfeng Ye <yeyunfeng@huawei.com>
---
v1 -> v2:
 - add "Fixes:" message

 tools/perf/builtin-kmem.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/tools/perf/builtin-kmem.c b/tools/perf/builtin-kmem.c
index 1e61e353f579..9661671cc26e 100644
--- a/tools/perf/builtin-kmem.c
+++ b/tools/perf/builtin-kmem.c
@@ -691,6 +691,7 @@ static char *compact_gfp_flags(char *gfp_flags)
 			new = realloc(new_flags, len + strlen(cpt) + 2);
 			if (new == NULL) {
 				free(new_flags);
+				free(orig_flags);
 				return NULL;
 			}

-- 
2.7.4.3


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH v2] perf kmem: Fix memory leak in compact_gfp_flags()
  2019-10-16 13:26 [PATCH v2] perf kmem: Fix memory leak in compact_gfp_flags() Yunfeng Ye
@ 2019-10-16 14:06 ` Arnaldo Carvalho de Melo
  2019-10-16 14:19   ` Yunfeng Ye
  0 siblings, 1 reply; 3+ messages in thread
From: Arnaldo Carvalho de Melo @ 2019-10-16 14:06 UTC (permalink / raw)
  To: Yunfeng Ye
  Cc: peterz, mingo, mark.rutland, alexander.shishkin, jolsa, namhyung,
	linux-kernel, hushiyuan, linfeilong

Em Wed, Oct 16, 2019 at 09:26:50PM +0800, Yunfeng Ye escreveu:
> The memory @orig_flags is allocated by strdup(), it is freed on the
> normal path, but leak to free on the error path.
> 
> Fix this by adding free(orig_flags) on the error path.
> 
> Fixes: 0e11115644b3 ("perf kmem: Print gfp flags in human readable string")
> Signed-off-by: Yunfeng Ye <yeyunfeng@huawei.com>
> ---
> v1 -> v2:
>  - add "Fixes:" message

No need for that, I did it already, just next time look for when the
problem you fixed was introduced, that way the various bots out there
can pick this up for backports, i.e. your fix has a higher chance of
being beneficial to more systems.

- Arnaldo
 
>  tools/perf/builtin-kmem.c | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/tools/perf/builtin-kmem.c b/tools/perf/builtin-kmem.c
> index 1e61e353f579..9661671cc26e 100644
> --- a/tools/perf/builtin-kmem.c
> +++ b/tools/perf/builtin-kmem.c
> @@ -691,6 +691,7 @@ static char *compact_gfp_flags(char *gfp_flags)
>  			new = realloc(new_flags, len + strlen(cpt) + 2);
>  			if (new == NULL) {
>  				free(new_flags);
> +				free(orig_flags);
>  				return NULL;
>  			}
> 
> -- 
> 2.7.4.3

-- 

- Arnaldo

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH v2] perf kmem: Fix memory leak in compact_gfp_flags()
  2019-10-16 14:06 ` Arnaldo Carvalho de Melo
@ 2019-10-16 14:19   ` Yunfeng Ye
  0 siblings, 0 replies; 3+ messages in thread
From: Yunfeng Ye @ 2019-10-16 14:19 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo
  Cc: peterz, mingo, mark.rutland, alexander.shishkin, jolsa, namhyung,
	linux-kernel, hushiyuan, linfeilong



On 2019/10/16 22:06, Arnaldo Carvalho de Melo wrote:
> Em Wed, Oct 16, 2019 at 09:26:50PM +0800, Yunfeng Ye escreveu:
>> The memory @orig_flags is allocated by strdup(), it is freed on the
>> normal path, but leak to free on the error path.
>>
>> Fix this by adding free(orig_flags) on the error path.
>>
>> Fixes: 0e11115644b3 ("perf kmem: Print gfp flags in human readable string")
>> Signed-off-by: Yunfeng Ye <yeyunfeng@huawei.com>
>> ---
>> v1 -> v2:
>>  - add "Fixes:" message
> 
> No need for that, I did it already, just next time look for when the
> problem you fixed was introduced, that way the various bots out there
> can pick this up for backports, i.e. your fix has a higher chance of
> being beneficial to more systems.
> 
Normally I will add "Fixes:", this time is forgot. thanks.

> - Arnaldo
>  
>>  tools/perf/builtin-kmem.c | 1 +
>>  1 file changed, 1 insertion(+)
>>
>> diff --git a/tools/perf/builtin-kmem.c b/tools/perf/builtin-kmem.c
>> index 1e61e353f579..9661671cc26e 100644
>> --- a/tools/perf/builtin-kmem.c
>> +++ b/tools/perf/builtin-kmem.c
>> @@ -691,6 +691,7 @@ static char *compact_gfp_flags(char *gfp_flags)
>>  			new = realloc(new_flags, len + strlen(cpt) + 2);
>>  			if (new == NULL) {
>>  				free(new_flags);
>> +				free(orig_flags);
>>  				return NULL;
>>  			}
>>
>> -- 
>> 2.7.4.3
> 


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2019-10-16 14:20 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-10-16 13:26 [PATCH v2] perf kmem: Fix memory leak in compact_gfp_flags() Yunfeng Ye
2019-10-16 14:06 ` Arnaldo Carvalho de Melo
2019-10-16 14:19   ` Yunfeng Ye

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).