Re: [PATCH v3] perf sched map: Add command-name, fuzzy-name options to filter the output map

From: Chen Yu
Date: Tue Jun 18 2024 - 10:10:41 EST


On 2024-06-17 at 18:19:30 +0530, Madadi Vineeth Reddy wrote:

> +static struct CommandList *parse_commands(const char *commands)
> +{
> + char *commands_copy = strdup(commands);

Should we check if commands_copy is NULL in case of allocation failure?

> + char *token = strtok(commands_copy, ",");
> + struct CommandList *cmd_list = malloc(sizeof(struct CommandList));
> +
> + if (cmd_list == NULL)
> + return NULL;
> +
> + cmd_list->command_count = 0;
> + cmd_list->command_list = NULL;
> +
> + while (token != NULL) {
> + cmd_list->command_list = realloc(cmd_list->command_list, sizeof(char *)
> + *(cmd_list->command_count + 1));
> + cmd_list->command_list[cmd_list->command_count] = strdup(token);

ditto.

thanks,
Chenyu