undetected array leak

Dec 22, 2014 at 2:50 PM
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.
Dec 23, 2014 at 7:15 PM
You're right, I've looked at the source, and VLD does not seem to differentiate between delete and delete[], or for that matter new and new[].

It's also possible to mix new[] and free, without any warning or memory leak being detected.
Dec 25, 2014 at 8:54 PM
I also found that if you have a base class and some other class is inherited from it and the base class does not have a virtual destructor , then VLD does not detect the leak.


--



Developer
Feb 25, 2015 at 3:06 PM
Allocation mismatches were never tested in VLD in the past. Though it would and should be an important feature. Therefore I would consider that unsupported at present. Though if anyone of you wants to pull the code, fix it, and then send a pull request, that would be awesome.
Marked as answer by KindDragon on 1/10/2016 at 2:31 AM
Mar 2, 2015 at 11:43 AM
I've already downloaded the latest source and am familiarizing myself with the code. I'm looking at the best way to implement this feature, so hopefully if I have a bit of spare time I'll get it done.