Skip to content

examples: fix static analyzer warning in fmapi-mctp - #60

Merged
davidlohr merged 1 commit into
computexpresslink:mainfrom
anisa-su993:fix-static-analyzer-warning
Aug 15, 2026
Merged

examples: fix static analyzer warning in fmapi-mctp#60
davidlohr merged 1 commit into
computexpresslink:mainfrom
anisa-su993:fix-static-analyzer-warning

Conversation

@anisa-su993

Copy link
Copy Markdown
Contributor
  1. When the command string contains no tokens, split_cmd_to_argv() assigns the allocated argv to *argvp and returns 0. The caller treats that as a failure and returns without freeing, which clang reports as a potential leak of 'argv'. Free argv and return -1 instead.

  2. fix loop in split_cmd_to_argv()

Cleanup loop originally freed "argv[argc]" argc times. Should free argv[i] instead.

printf("Failed to allocate argv.\n");
        for (i = 0; i < argc; i++) {
            free(argv[argc]);
        }

1. When the command string contains no tokens, split_cmd_to_argv() assigns the
allocated argv to *argvp and returns 0. The caller treats that as a failure
and returns without freeing, which clang reports as a potential leak of
'argv'. Free argv and return -1 instead.

2. fix loop in split_cmd_to_argv()

Cleanup loop originally freed "argv[argc]" argc times.
Should free argv[i] instead.

	printf("Failed to allocate argv.\n");
            for (i = 0; i < argc; i++) {
                free(argv[argc]);
            }

Signed-off-by: Anisa Su <anisa.su@samsung.com>
@davidlohr
davidlohr merged commit 9381bca into computexpresslink:main Aug 15, 2026
27 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants