FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Fix #14949: FP leakNoVarFunctionCall when passing resource to constructor by ludviggunne · Pull Request #8764 · cppcheck-opensource/cppcheck · GitHub

Fix #14949: FP leakNoVarFunctionCall when passing resource to constructor - #8764

Open
ludviggunne wants to merge 2 commits into
cppcheck-opensource:mainfrom
ludviggunne:14949-mkostemp
Open

Fix #14949: FP leakNoVarFunctionCall when passing resource to constructor#8764
ludviggunne wants to merge 2 commits into
cppcheck-opensource:mainfrom
ludviggunne:14949-mkostemp

Conversation

Copy link
Copy Markdown
Collaborator

No description provided.

Comment thread lib/checkmemoryleak.cpp Fixed

Copy link
Copy Markdown
Collaborator

I wonder why we need so much new code, when there already is a true negative for this:

struct S {
    explicit S(void* p) {
        m = p;
    }
    ~S() {
      free(m);
    }
    void* m = 0;
};

S g(size_t n) {
    return S(malloc(n));
}

void f() {
    S s = g(100);
}

Also see the OP in the forum.

Copy link
Copy Markdown
Collaborator Author

I wonder why we need so much new code, when there already is a true negative for this:

There is a false negative if you remove the call to free. But that's because of this early continue that I don't really understand: https://github.com/cppcheck-opensource/cppcheck/pull/8764/changes#diff-006278020c4bf4fcbe45fbeaeca784b14316e77ceb303853101406d62a7473beR1120.

Also see the OP in the forum.

CheckMemoryLeakInClassImpl only looks for allocations/deallocations in the constructor/destructor, in this case it's allocated outside of the constructor. But yes I should probably reuse some code from that check.

ludviggunne marked this pull request as draft July 29, 2026 14:33

Copy link
Copy Markdown
Collaborator Author

But yes I should probably reuse some code from that check.

Actually I think it's to coupled with the error reporting to be reused in an effective way, so I'll stick with this.

ludviggunne marked this pull request as ready for review July 30, 2026 06:43
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants


Back | FazBrowse Home | New Git URL