Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual Leak Detector not finding leaks VS2013

I can't seem to make VLD catch any memory leaks no matter what I tried. Any ideas why ?

Here snippet of the output too:

Visual Leak Detector Version 2.4RC2 installed. 
The thread 0x5748 has exited with code 0 (0x0).
The thread 0x2c70 has exited with code 0 (0x0).
The thread 0x3c98 has exited with code 0 (0x0).
No memory leaks detected.
Visual Leak Detector is now exiting.
The program '[24988] ConsoleApplication2.exe' has exited with code 0 (0x0).


#include <vld.h>

#include <iostream>
using namespace std;

class Car{
    public:
        Car() {}

        Car(string model,int year, string color) {
            this->model = model; this->color, this->year = year;
        }

        string getModel() {
            return this->model;
        }

        void setModel(string m) {
            this->model = model;
        }

        string getColor() {
            return this->color;
        }

        void setColor(string color) {
            this->color = color;
        }

        void paint()
        {
            setColor("white");
        }

    private:
        string model;
        int year;
        string color;
};


int _tmain(int argc, _TCHAR* argv[]){
    Car c("bmw", 2000, "red");
    c.paint();
    cout << c.getColor().c_str();

    for (int i = 0; i < 10; i++)
        int *ptr = new int(10);

    Car *c2 = new Car("benz", 2010, "yellow");

    return 0;
 }

What am I missing ?

like image 451
user1529412 Avatar asked Oct 16 '15 22:10

user1529412


People also ask

How do you pinpoint memory leaks?

The primary tools for detecting memory leaks are the C/C++ debugger and the C Run-time Library (CRT) debug heap functions. The #define statement maps a base version of the CRT heap functions to the corresponding debug version. If you leave out the #define statement, the memory leak dump will be less detailed.

What causes memory leaks in C++?

Memory leakage occurs in C++ when programmers allocates memory by using new keyword and forgets to deallocate the memory by using delete() function or delete[] operator. One of the most memory leakage occurs in C++ by using wrong delete operator.

What is visual leak detector?

Visual Leak Detector (Support Visual Studio 2019 16.7)Provides a complete stack trace for each leaked block, including source file and line number information when available. Detects most, if not all, types of in-process memory leaks including COM-based leaks, and pure Win32 heap-based leaks.

How detect memory leaks C++ Linux?

Mtrace. Mtrace is a memory-debugging tool included in the GNU C library. It works with both C and C++ programs on Linux, and detects memory leaks caused by unbalanced calls to the malloc() and free() functions.


1 Answers

It's working under visual studio 2013 ultimate

You have to execute the program in a console mode (go to the debug directory of the project)

In the following, you will find a picture of the result, but the console displayed many leaks we can't see all of them here

I added the include and lib paths to the project setting

  1. C:\Program Files (x86)\Visual Leak Detector\include
  2. C:\Program Files (x86)\Visual Leak Detector\lib\win32
  3. C:\Program Files (x86)\Visual Leak Detector\lib\win64

enter image description here

As you see there is 13 memory leaks.

like image 66
HDJEMAI Avatar answered Oct 02 '22 18:10

HDJEMAI