The following small app reports a memory leak in version 1.85 and before, but reports no problem in 1.86 and after. Is this expected behavior? We have made mistakes like this in the past and it was great to have a check.
If you would like to investigate how to solve this then please feel free to do it. A guess is that we added a bailout when pointer is modified.. so if you find the bailout you can try to make it less stupid.
I tried to run tests and such, but I wasn't yet able to get the tests to run.
Strange how do you compile and run?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Thanks @danielmarjamaki
I would be up for trying to help. I cloned the Github repo. There are nice instructions on getting the cppcheck binary built, but no instructions on running the tests that I could find. And to be honest I use other languages much more frequently and my C compilation skills are lacking.
Can you point me to any steps to getting the tests running? Or is there a test framework library being used that I can read up on?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Sorry about the x+-1; line in the original post, That was a red-herring. I had included it because otherwise cppcheck finds an unused var warning with enabled=all turned on.
I hope this helps! I don't think I'm knowledgeable enough with this code base to implement this feature.
Last edit: Jesse Smith 2020-12-19
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
The following small app reports a memory leak in version 1.85 and before, but reports no problem in 1.86 and after. Is this expected behavior? We have made mistakes like this in the past and it was great to have a check.
I tried to run tests and such, but I wasn't yet able to get the tests to run.
Thanks I have created https://trac.cppcheck.net/ticket/10050
If you would like to investigate how to solve this then please feel free to do it. A guess is that we added a bailout when pointer is modified.. so if you find the bailout you can try to make it less stupid.
Strange how do you compile and run?
Thanks @danielmarjamaki
I would be up for trying to help. I cloned the Github repo. There are nice instructions on getting the cppcheck binary built, but no instructions on running the tests that I could find. And to be honest I use other languages much more frequently and my C compilation skills are lacking.
Can you point me to any steps to getting the tests running? Or is there a test framework library being used that I can read up on?
it depends on how you compile. Makefile/CMake/visual studio.
Makefile: make test
CMake: cmake -DBUILD_TESTS=On .. && make check
Cool got the tests working, had to brew reinstall pcre...
This appears to have been the offending commit, but I see it's tied to a bigger complex project.
https://github.com/danmar/cppcheck/commit/822718878669152e62453fdc95c2221ddc969f70
I added a failing test for the mem-leak-in-loop case and opened a PR: https://github.com/danmar/cppcheck/pull/2961
the case
Sorry about the x+-1; line in the original post, That was a red-herring. I had included it because otherwise cppcheck finds an unused var warning with enabled=all turned on.
I hope this helps! I don't think I'm knowledgeable enough with this code base to implement this feature.
Last edit: Jesse Smith 2020-12-19