Menu

Mem leak not detected as of 1.86

2020-12-16
2020-12-19
  • Jesse Smith

    Jesse Smith - 2020-12-16

    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.

    int main() {
        while(true) {
            char* x = malloc(100);
            x+=1;
        }  
        return 0;
    }
    
     
  • Jesse Smith

    Jesse Smith - 2020-12-16

    I tried to run tests and such, but I wasn't yet able to get the tests to run.

     
  • Daniel Marjamäki

    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.

    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?

     
  • Jesse Smith

    Jesse Smith - 2020-12-18

    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?

     
  • Daniel Marjamäki

    it depends on how you compile. Makefile/CMake/visual studio.
    Makefile: make test
    CMake: cmake -DBUILD_TESTS=On .. && make check

     
  • Jesse Smith

    Jesse Smith - 2020-12-19

    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

    void main()
    {
          while (1)
          {
                char *p = malloc(100);
          }
    }
    

    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

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.