Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753593AbbEIHRV (ORCPT ); Sat, 9 May 2015 03:17:21 -0400 Received: from szxga01-in.huawei.com ([58.251.152.64]:46001 "EHLO szxga01-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751210AbbEIHRT (ORCPT ); Sat, 9 May 2015 03:17:19 -0400 Message-ID: <554DB45D.3040507@huawei.com> Date: Sat, 9 May 2015 15:16:45 +0800 From: He Kuang User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:31.0) Gecko/20100101 Thunderbird/31.3.0 MIME-Version: 1.0 To: Masami Hiramatsu , , , , CC: , Subject: Re: [PATCH 1/3] perf probe: Remove length limitation for showing available variables References: <1431087832-46889-1-git-send-email-hekuang@huawei.com> <554CC586.6070504@hitachi.com> In-Reply-To: <554CC586.6070504@hitachi.com> Content-Type: text/plain; charset="iso-2022-jp" Content-Transfer-Encoding: 7bit X-Originating-IP: [10.110.54.65] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1916 Lines: 65 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, > >> >> > -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/