1

I had a C++ program that I was running within a bash script, and I wanted to see if the program was leaking memory, so I did valgrind ./doTheThing.sh and it reported 12 bytes of memory leaked. I figured my program wasn't structured well, so I made some changes, tried again, and still the same 12 bytes of memory were being leaked. After I tried enough different things to make the C++ program not leak memory and getting the exact same leak, I tried making the program malloc 100,000 bytes and then exit and...12 bytes of memory leaked. Then I ran the program on its own outside of the script and the memory leaks showed up in ways that actually made sense.

So the problem was running valgrind on a bash script. Is this because valgrind wasn't meant to be used on bash scripts and glitches in a way that makes it look like it leaks 12 bytes of memory? Or do bash scripts inherently leak 12 bytes of memory every time they run?

  • https://stackoverflow.com/questions/301576/how-do-i-tell-valgrind-to-memcheck-forked-processes – Mat May 09 '20 at 16:17
  • Does it matter? If the bytes are leaked but the program is shutting down anyway, it doesn't really matter. Memory leaks only really matter for long running programs. It's not like leaks persist across program invocations. – Jesper Juhl May 09 '20 at 16:17
  • @JesperJuhl Not particularly in this instance, but I'm asking so I can learn more about how both valgrind and memory allocation works – Alejandro Servetto May 09 '20 at 16:21
  • Aren't you running Valgrind on bash rather than your program now? – that other guy May 09 '20 at 16:26
  • @thatotherguy yeah, my question is about why bash reports 12 bytes of memory leak every time it runs – Alejandro Servetto May 11 '20 at 02:56
  • There appears to be some further investigation here: https://stackoverflow.com/questions/53553905/is-bash-leaking-memory – that other guy May 11 '20 at 03:05

0 Answers0