简体   繁体   中英

running valgrind

I have not used valgrind before, but I need to use it to check memory leak. I ran the following command:

G_SLICE=always-malloc G_DEBUG=gc-friendly  valgrind -v --tool=memcheck --leak-check=full --num-callers=40 --log-file=valgrind.log example1
valgrind: example1: command not found

I followed instructions from this site: http://www.cprogramming.com/debugging/valgrind.html

this is what the example1 file looks like:

#include <stdlib.h>
int main()
{
    char *x = malloc(100); /* or, in C++, "char *x = new char[100] */
    return 0;
}

I know valgrind is installed on my machine, regardless I ran the following command to make sure:

sudo apt-get install valgrind

Can somebody pls. guide me how to get valgrind working....thx!

You forgot to give it the path to the program you wanted to run! Replace example1 with the path to the executable.

For example:

G_SLICE=always-malloc G_DEBUG=gc-friendly  valgrind -v \
  --tool=memcheck --leak-check=full --num-callers=40 \
  --log-file=valgrind.log ./example1

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM