In the following snippet, cppcheck does not report a memleak if the return value is explicitly compared against a value, as in the case of a2. But at the same time, if we just check if (getaddrinfo()) as in the case of a1, which is a widely used pattern to check if the function returned zero or not, it reports a false positive memleak. Invocation command was cppcheck --library=posix.cfg main.c, and the version was 2.14.2
In the following snippet, cppcheck does not report a memleak if the return value is explicitly compared against a value, as in the case of a2. But at the same time, if we just check
if (getaddrinfo())
as in the case of a1, which is a widely used pattern to check if the function returned zero or not, it reports a false positive memleak. Invocation command wascppcheck --library=posix.cfg main.c
, and the version was 2.14.2It would be nice if you could treat
if (func())
same asif (func() != 0)
.Thanks for reporting, fixed by https://github.com/danmar/cppcheck/pull/6671
Thank you! That was really fast :)