Menu

Possible false negative

2020-10-06
2020-10-09
  • João M. S. Silva

    Hi,
    Is it possible that a memory leak was occurring because of a missing virtual destructor?
    virtual ~ClassName() {}
    If the default behaviour of the virtual destructor prevents the leak, why didn't cppcheck warn about it?
    Thanks.

     
  • Daniel Marjamäki

    could you show a minimal example code where there is a leak and we do not warn?

     
  • João M. S. Silva

    Not sure. Does this help?

    "It's not a new/delete - the ClassName code uses smart pointers

    I suspected we were passing around a std::shared_ptr<namespace::classname> </namespace::classname>

    Which actually pointed to a derived builder and the lack of virtual destructor on ClassName meant the derived destructor wasn't called when the shared pointer went out of scope"

     
  • João M. S. Silva

    Is this enough or must I really provide an example?

     
  • Daniel Marjamäki

    I managed to put together an example. And created this ticket:
    https://trac.cppcheck.net/ticket/9947

     
  • João M. S. Silva

    Many thanks.

     

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.