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 [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Reply via email to