Valgrind False Positive

Sep 8, 2017 at 5:55pm
Hi all,

I have installed Bash on Ubuntu for Windows 10 and would like to be able to use Valgrind as well. However, upon running a simple hello world program for testing, the output of Valgrind states that I have a memory leak? The command I gave for installing Valgrind was: "apt install valgrind" (running as root). The current release I have of Ubuntu is: "16.04.3 LTS xenial". Also, I have installed gcc and g++ by "apt install gcc" and "apt install g++" respectively. Any ideas on how I can fix this? Thanks for any and all help.

1
2
3
4
5
6
7
8
#include <iostream>
using namespace std;

int main()
{
    cout << "Hello World\n";
    return 0;
}
Sep 8, 2017 at 8:11pm
I have not used these kinds of tools in a while but if I recall you can configure the warning level and options somewhere to reduce the junk results.

But you can never really fully get 100% accuracy. They will always miss a little, and they will always flag valid code as bad. You just have to take a look at each complaint as a human and decide if it is broken or not. Also you can do a memory leak test and only use the tool when you know you have an actual leak.
Sep 8, 2017 at 8:53pm
I have a memory leak

What's the error message? Please share the output, verbatim.

Which version of valgrind are you using?
Which version of g++ are you using?
How are you compiling the code? (command line)
How are you running valgrind? (command line)

On my system:

% g++ -Wall -Wextra -pedantic-errors -std=c++17 -ggdb hello-world.cxx -ohello-world
% valgrind hello-world
% clang++ -Wall -Wextra -pedantic-errors -std=c++1z -ggdb hello-world.cxx -ohello-world
% valgrind hello-world
% clang++5.0 -Wall -Wextra -pedantic-errors -std=c++17 -ggdb -stdlib=libstdc++ hello-world.cxx -ohello-world
% valgrind hello-world

With G++ 7.1.1, Clang 4.0.1, experimental Clang 5.0.0 and Valgrind 3.13.0
I don't get any errors.

If the errors are coming from the standard library or the CRT, you are probably okay. The CRT of all things is allowed to make assumptions about the system's ability to clean resources it fails to free on it's own.

On another note, it's time to compile GCC & LLVM/Clang again... *sigh* :)
Last edited on Sep 8, 2017 at 8:55pm
Topic archived. No new replies allowed.