[5/5] perf thread_map: Free strlist on normal path in thread_map__new_by_tid_str()

Message ID 20240205104616.132417-6-yangjihong1@huawei.com
State New
Headers
Series [1/5] perf sched: Move start_work_mutex and work_done_wait_mutex initialization to perf_sched__replay() |

Commit Message

Yang Jihong Feb. 5, 2024, 10:46 a.m. UTC
  slist needs to be freed in both error path and normal path in
thread_map__new_by_tid_str().

Signed-off-by: Yang Jihong <yangjihong1@huawei.com>
---
 tools/perf/util/thread_map.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
  

Comments

Arnaldo Carvalho de Melo Feb. 5, 2024, 7:09 p.m. UTC | #1
On Mon, Feb 05, 2024 at 10:46:16AM +0000, Yang Jihong wrote:
> slist needs to be freed in both error path and normal path in
> thread_map__new_by_tid_str().

Please add:

Fixes: b52956c961be3a04 ("perf tools: Allow multiple threads or processes in record, stat, top")

Reviewed-by: Arnaldo Carvalho de Melo <acme@redhat.com>

- Arnaldo
 
> Signed-off-by: Yang Jihong <yangjihong1@huawei.com>
> ---
>  tools/perf/util/thread_map.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/tools/perf/util/thread_map.c b/tools/perf/util/thread_map.c
> index e848579e61a8..ea3b431b9783 100644
> --- a/tools/perf/util/thread_map.c
> +++ b/tools/perf/util/thread_map.c
> @@ -280,13 +280,13 @@ struct perf_thread_map *thread_map__new_by_tid_str(const char *tid_str)
>  		threads->nr = ntasks;
>  	}
>  out:
> +	strlist__delete(slist);
>  	if (threads)
>  		refcount_set(&threads->refcnt, 1);
>  	return threads;
>  
>  out_free_threads:
>  	zfree(&threads);
> -	strlist__delete(slist);
>  	goto out;
>  }
>  
> -- 
> 2.34.1
  
Yang Jihong Feb. 6, 2024, 7:10 a.m. UTC | #2
Hello,

On 2024/2/6 3:09, Arnaldo Carvalho de Melo wrote:
> On Mon, Feb 05, 2024 at 10:46:16AM +0000, Yang Jihong wrote:
>> slist needs to be freed in both error path and normal path in
>> thread_map__new_by_tid_str().
> 
> Please add:
> 
> Fixes: b52956c961be3a04 ("perf tools: Allow multiple threads or processes in record, stat, top")
> 
OK, will add fixes tag in v2.

> Reviewed-by: Arnaldo Carvalho de Melo <acme@redhat.com>
> 
Thanks for the reviewed-by tag

> - Arnaldo

Thanks,
Yang
  

Patch

diff --git a/tools/perf/util/thread_map.c b/tools/perf/util/thread_map.c
index e848579e61a8..ea3b431b9783 100644
--- a/tools/perf/util/thread_map.c
+++ b/tools/perf/util/thread_map.c
@@ -280,13 +280,13 @@  struct perf_thread_map *thread_map__new_by_tid_str(const char *tid_str)
 		threads->nr = ntasks;
 	}
 out:
+	strlist__delete(slist);
 	if (threads)
 		refcount_set(&threads->refcnt, 1);
 	return threads;
 
 out_free_threads:
 	zfree(&threads);
-	strlist__delete(slist);
 	goto out;
 }