lkml.org 
[lkml]   [2021]   [May]   [25]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
SubjectRe: [PATCH v1 4/5] perf mem: Support record for hybrid platform
From
Date
Hi Jiri,

>>>       rec_argv = calloc(rec_argc + 1, sizeof(char *));
>>>       if (!rec_argv)
>>>           return -1;
>>> +    /*
>>> +     * Save the allocated event name strings.
>>> +     */
>>> +    rec_tmp = calloc(rec_argc + 1, sizeof(char *));
>>> +    if (!rec_tmp) {
>>> +        free(rec_argv);
>>> +        return -1;
>>> +    }
>>
>> why not do strdup on all of them and always call free instead?
>> that would get rid of the rec_tmp and tmp_nr
>>
>
> That is also one method. Let me try it.
>

If we do strdup on all of them, such as,

if (e->record)
rec_argv[i++] = strdup("-W");

rec_argv[i++] = strdup("-d");

if (mem->phys_addr)
rec_argv[i++] = strdup("--phys-data");
....

That looks too much strdup used here. So I choose to use a rec_tmp[] to record the allocated string
and free them before exit the function.

Or we record the start index and end index in rec_argv[] for the allocated event string, use strdup
on them and call free before exit the function.

What do you think?

Thanks
Jin Yao

\
 
 \ /
  Last update: 2021-05-25 10:09    [W:0.110 / U:0.572 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site