I have run across a false positive and have created a minimal reproducer. If I assign a string member of a struct inside a switch / case but return on default, it thinks there is a leak on the default path.
Line 15 is the return NULL. I have tested this on 1.80, 1.83, and current git. They all report the same thing. The leak is only reported when the posix library is used. This is where it picks up that strdup is an allocator.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hello,
I have run across a false positive and have created a minimal reproducer. If I assign a string member of a struct inside a switch / case but return on default, it thinks there is a leak on the default path.
Which is tested thusly:
cppcheck --library=posix break.c
[break.c:15]: (error) Memory leak: subj.str
Line 15 is the return NULL. I have tested this on 1.80, 1.83, and current git. They all report the same thing. The leak is only reported when the posix library is used. This is where it picks up that strdup is an allocator.
This reproduces with v2.3 even without
--library=posix
.I have created a ticket: https://trac.cppcheck.net/ticket/10152