Stackyquest
Stackyquest

Reputation: 11

How to run Valgrind and other tools to check memory leaks in Visual studio code?

I have installed "Valgrind Task Integration" extension in Visual studio code and after restarting VS code and typed the following Valgrind command in terminal, "valgrind --leak-check=full --show-leak-kinds=all --track-origins=yes --verbose --log-file=valgrind-out.txt .mem_leak_fix" for fixing memory leak issue for my sample C test code shown below,

#include <stdio.h>
#include <stdlib.h>

int main(void)
{
    int* mptr = malloc(sizeof(int));
    int* mptr1 = malloc(sizeof(int));
    *mptr = 10;
    *mptr1 = 20;
    printf("mptr: %d\n",*mptr);
    printf("mptr1: %d\n",*mptr1);
    free(mptr1);
    mptr1=NULL; 
    return 0;
}

I am getting "The term 'valgrind' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again".

I have searched long time to know how to perform memory leak checks in visual studio for long time. Kindly let me know how to install memory leak debugger tools in Visual studio and perform memory leak operations. Kindly help me on this

Upvotes: 1

Views: 8329

Answers (1)

Paul Floyd
Paul Floyd

Reputation: 6906

Learn to run Valgrind in a terminal. It will be just sooo much easier to begin with as you will only be learning one thing - Valgrind, and not two things - Valgrind and VS code.

Next, start with the simplest options. You shouldn't be starting with --verbose. I only recommend --track-origins=yes after you have found errors.

Valgrind does not run natively on Windows. You will need to install one of the supported platforms, see https://valgrind.org/info/platforms.html. You may be able to use WSL2 https://learn.microsoft.com/en-us/windows/wsl/install or use something like VirtualBox or VMware or similar.

Upvotes: 1

Related Questions