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

Commented Issue: False detection with static objects [10141]

$
0
0
In the code below VLD detects a memory leak if TestClass and getStaticObject are defined in a DLL. The DLL is built without VLD.

```
// some.dll

class TestClass
{
public:
TestClass()
{
buffer = new char[10];
}
~TestClass()
{
delete[] buffer;
}
private:
char* buffer;
};

TestClass& getStaticObject(void)
{
static TestClass object;
return object;
}

// ...

// end of some.dll

int main()
{
getStaticObject();
return 0;
}

```
Comments: VLD has no means of knowing that you were allocating a static object. You can either cause all your static objects to get initialized, then report all leaks as detected, then proceed with finding your leaks, or you can temporarily disable VLD by calling VLDDisable() when initializing your static objects. Beware of threading issues though if your application allocates memory from multiple threads.

Viewing all articles
Browse latest Browse all 704

Trending Articles



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