Skip to content

Revisit false-positives in static initialization #4

@mattdurak

Description

@mattdurak

Ideally VLD should detect this leak:

#include <stdlib.h>
static void* v = malloc(1); // allocation of raw pointer, no automatic free
int main()
{
    // do something with v
    return 0;
}

But should not detect this:

#include <string>
static std::string s("my string"); // allocates string but destructor will be called at exit
int main()
{
    // something using s
    return 0;
}

The current solution will not detect either of those cases as leaks.

We could do better by seeing static initializations with constructors in the stack and assuming that destructors will be called. That is slightly more complex than the existing logic, but could be done without too much difficulty. Then we could still consider the code above a leak, that could be "fixed" with an explicit free call.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions