From: He Kuang <hekuang@huawei.com>
To: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>,
<a.p.zijlstra@chello.nl>, <acme@kernel.org>, <jolsa@kernel.org>,
<mingo@redhat.com>
Cc: <wangnan0@huawei.com>, <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH 1/3] perf probe: Remove length limitation for showing available variables
Date: Sat, 9 May 2015 15:16:45 +0800 [thread overview]
Message-ID: <554DB45D.3040507@huawei.com> (raw)
In-Reply-To: <554CC586.6070504@hitachi.com>
On 2015/5/8 22:17, Masami Hiramatsu wrote:
> On 2015/05/08 21:23, He Kuang wrote:
>> Use struct strbuf instead of bare char[] to remove the length limitation
>> of variables in variable_list, so they will not disappear due to
>> overlength, and make preparation for adding more description for
>> variables.
> Looks good to me, except one memory leak. please see below.
Oh yes, thanks!
>> }
>>
>> -#define MAX_VAR_LEN 64
>> -
>> /* Collect available variables in this scope */
>> static int collect_variables_cb(Dwarf_Die *die_mem, void *data)
>> {
>> struct available_var_finder *af = data;
>> struct variable_list *vl;
>> - char buf[MAX_VAR_LEN];
>> + struct strbuf buf;
>> int tag, ret;
>>
>> vl = &af->vls[af->nvls - 1];
>> + strbuf_init(&buf, 64);
>>
>> tag = dwarf_tag(die_mem);
>> if (tag == DW_TAG_formal_parameter ||
>> @@ -1257,10 +1256,13 @@ static int collect_variables_cb(Dwarf_Die *die_mem, void *data)
>> af->pf.fb_ops, &af->pf.sp_die,
>> NULL);
>> if (ret == 0) {
strbuf_init() should be called here to avoid useless malloc.
>> - ret = die_get_varname(die_mem, buf, MAX_VAR_LEN);
>> - pr_debug2("Add new var: %s\n", buf);
>> - if (ret > 0)
>> - strlist__add(vl->vars, buf);
>> + ret = die_get_varname(die_mem, &buf);
>> + pr_debug2("Add new var: %s\n", buf.buf);
>> + if (ret == 0) {
>> + strlist__add(vl->vars,
>> + strbuf_detach(&buf, NULL));
>> + }
>> + strbuf_release(&buf);
> It seems that this strbuf_release() should be called in any case,
> since strbuf_init already allocated buffer.
>
>> }
>> }
> so here is the good place to call, isn't it?
>
> Thank you,
>
>>
>>
>
prev parent reply other threads:[~2015-05-09 7:17 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-05-08 12:23 [PATCH 1/3] perf probe: Remove length limitation for showing available variables He Kuang
2015-05-08 12:23 ` [PATCH 2/3] perf probe: Add flag for options when showing variables He Kuang
2015-05-08 13:15 ` Masami Hiramatsu
2015-05-09 6:30 ` He Kuang
2015-05-08 12:23 ` [PATCH 3/3] perf probe: Add --range option to show variable location range He Kuang
2015-05-08 14:08 ` Masami Hiramatsu
2015-05-09 7:41 ` He Kuang
2015-05-10 3:02 ` Masami Hiramatsu
2015-05-08 14:17 ` [PATCH 1/3] perf probe: Remove length limitation for showing available variables Masami Hiramatsu
2015-05-09 7:16 ` He Kuang [this message]
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=554DB45D.3040507@huawei.com \
--to=hekuang@huawei.com \
--cc=a.p.zijlstra@chello.nl \
--cc=acme@kernel.org \
--cc=jolsa@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=masami.hiramatsu.pt@hitachi.com \
--cc=mingo@redhat.com \
--cc=wangnan0@huawei.com \
/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