From: Yang Jihong <yangjihong1@huawei.com>
To: Arnaldo Carvalho de Melo <acme@kernel.org>
Cc: <peterz@infradead.org>, <mingo@redhat.com>, <namhyung@kernel.org>,
<mark.rutland@arm.com>, <alexander.shishkin@linux.intel.com>,
<jolsa@kernel.org>, <irogers@google.com>,
<adrian.hunter@intel.com>, <linux-perf-users@vger.kernel.org>,
<linux-kernel@vger.kernel.org>
Subject: Re: [PATCH 2/5] perf sched: Fix memory leak in perf_sched__map()
Date: Tue, 6 Feb 2024 15:08:09 +0800 [thread overview]
Message-ID: <9909979e-3123-60a0-05e7-e770c705416e@huawei.com> (raw)
In-Reply-To: <ZcEv5BBvNEye4ZYf@x1>
Hello,
On 2024/2/6 2:58, Arnaldo Carvalho de Melo wrote:
> On Mon, Feb 05, 2024 at 10:46:13AM +0000, Yang Jihong wrote:
>> +++ b/tools/perf/builtin-sched.c
>> @@ -3267,20 +3264,34 @@ static int setup_color_cpus(struct perf_sched *sched)
>>
>> static int perf_sched__map(struct perf_sched *sched)
>> {
>> + int rc = -1;
>> +
>> if (setup_map_cpus(sched))
>> - return -1;
>> + return rc;
>>
>> if (setup_color_pids(sched))
>> - return -1;
>> + goto out_free_map_cpus;
>
> I think renaming the goto labels to what they will do, dropping a
> refcount, is more clear, i.e.:
>
> goto out_put_map_cpus;
OK, will modify in v2.
>
>>
>> if (setup_color_cpus(sched))
>> - return -1;
>> + goto out_free_color_pids;
>>
>> setup_pager();
>> if (perf_sched__read_events(sched))
>> - return -1;
>> + goto out_free_color_cpus;
>> +
>> + rc = 0;
>> print_bad_events(sched);
>> - return 0;
>> +
>> +out_free_color_cpus:
>> + perf_cpu_map__put(sched->map.color_cpus);
>> +
>> +out_free_color_pids:
>> + perf_thread_map__put(sched->map.color_pids);
>> +
>> +out_free_map_cpus:
>> + free(sched->map.comp_cpus);
>
> Please use:
>
> zfree(&sched->map.comp_cpus);
>
OK, will change to use zfree in the next version.
Other patches where uses free will also be changed to zfree.
Thanks,
Yang
next prev parent reply other threads:[~2024-02-06 7:08 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-02-05 10:46 [PATCH 0/5] perf sched: Minor optimizations for resource initialization Yang Jihong
2024-02-05 10:46 ` [PATCH 1/5] perf sched: Move start_work_mutex and work_done_wait_mutex initialization to perf_sched__replay() Yang Jihong
2024-02-05 10:46 ` [PATCH 2/5] perf sched: Fix memory leak in perf_sched__map() Yang Jihong
2024-02-05 18:58 ` Arnaldo Carvalho de Melo
2024-02-06 7:08 ` Yang Jihong [this message]
2024-02-05 10:46 ` [PATCH 3/5] perf sched: Move curr_thread initialization to perf_sched__map() Yang Jihong
2024-02-05 18:59 ` Arnaldo Carvalho de Melo
2024-02-05 10:46 ` [PATCH 4/5] perf sched: Move curr_pid and cpu_last_switched initialization to perf_sched__{lat|map|replay}() Yang Jihong
2024-02-05 19:01 ` Arnaldo Carvalho de Melo
2024-02-05 10:46 ` [PATCH 5/5] perf thread_map: Free strlist on normal path in thread_map__new_by_tid_str() Yang Jihong
2024-02-05 19:09 ` Arnaldo Carvalho de Melo
2024-02-06 7:10 ` Yang Jihong
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=9909979e-3123-60a0-05e7-e770c705416e@huawei.com \
--to=yangjihong1@huawei.com \
--cc=acme@kernel.org \
--cc=adrian.hunter@intel.com \
--cc=alexander.shishkin@linux.intel.com \
--cc=irogers@google.com \
--cc=jolsa@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-perf-users@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=mingo@redhat.com \
--cc=namhyung@kernel.org \
--cc=peterz@infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®