Quantcast
Channel: Visual Leak Detector for Visual C++ 2008-2015
Viewing all articles
Browse latest Browse all 704

New Post: undetected array leak

$
0
0
hello
I just downloaded the vld lib and test it with the following code:
class Leak 
{
public:
    Leak(const std::string& str) 
    {
        c = new char[str.length()]();
        memcpy(c, str.c_str(), str.length());
    }

    void print()
    {
        std::cout << c << std::endl;
    }
    ~Leak()
    {
        delete c;
    }
private:
    char* c;
};

class LeakHolder 
{
public:
    LeakHolder()
    {
        leak.reset(new Leak("Hello World!"));
    }
private:
    std::unique_ptr<Leak> leak;
    
};
int _tmain(int argc, _TCHAR* argv[])
{
    
    LeakHolder lh;
    return 0;
}
this code is leaking the array memory since the delete is deleting only the first char and not the all array, but the library didn't report any memory leak.
when i removed the delete completely the detection was ok.

Viewing all articles
Browse latest Browse all 704

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>