Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

libc: common: Ignore GCC analyzer-malloc-leak warning #77846

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

golowanow
Copy link
Member

@golowanow golowanow commented Aug 31, 2024

Ignore GCC static analyzer warning (analyzer-malloc-leak) on malloc() and realloc() return values as false positive.

west build -p -b qemu_x86 tests/kernel/timer/timer_api -DZEPHYR_SCA_VARIANT=gcc

[110/142] Building C object zephyr/lib/libc/common/CMakeFiles/lib__libc__common.dir/source/stdlib/malloc.c.obj
/foo/zephyr/lib/libc/common/source/stdlib/malloc.c: In function 'malloc':
/foo/zephyr/lib/libc/common/source/stdlib/malloc.c:153:16: warning: leak of 'ret' [CWE-401] [-Wanalyzer-malloc-leak] 
...
[113/143] Building C object zephyr/lib/libc/common/CMakeFiles/lib__libc__common.dir/source/stdlib/malloc.c.obj
/foo/zephyr/lib/libc/common/source/stdlib/malloc.c: In function 'realloc':
/foo/zephyr/lib/libc/common/source/stdlib/malloc.c:253:16: warning: leak of 'realloc(ptr,  __real__ .MUL_OVERFLOW (nmemb_4(D), size_12(D)))' [CWE-401] [-Wanalyzer-malloc-leak]

This warning, for example, is 102 of 108 build errors for qemu_x86 on ./tests/kernel/* (v3.7.0-1999-g7cf124b4a964) with GCC static analyzer

./scripts/twister -b -p qemu_x86 -x=ZEPHYR_SCA_VARIANT=gcc -T ./tests/kernel
...
INFO    - Total complete:  192/ 192  100%  skipped:   72, failed:    0, error:  108                                          
INFO    - 192 test scenarios (192 test instances) selected, 72 configurations skipped (58 by static filter, 14 at runtime).  
INFO    - 12 of 192 test configurations passed (10.00%), 0 failed, 108 errored, 72 skipped with 0 warnings in 533.02 seconds 
...	
grep -Ee "malloc\.c:153:16: error:.*CWE-401" ./twister-out/**/build.log | wc -l
102

Ignore GCC static analyzer warning (analyzer-malloc-leak)
on malloc() and realloc() return values as false positive.

Signed-off-by: Dmitrii Golovanov <[email protected]>
@golowanow golowanow force-pushed the stdlib-gcc-analyzer-warn_20240831 branch from 195fe18 to 4aa6310 Compare August 31, 2024 18:19
@golowanow golowanow marked this pull request as ready for review August 31, 2024 20:02
@zephyrbot zephyrbot added the area: C Library C Standard Library label Aug 31, 2024
Copy link
Collaborator

@pdgendt pdgendt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think #64159 provides a better fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: C Library C Standard Library
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants