0

I'm a beginner in C, and I'm wondering why this simple Hello World program has a memory leak:

 #include <stdio.h>
 int main(int argc, const char *argv[]) {
   printf("Hello world\n");
   return 0;
 }

It compiles, but this is what Valgrind reports:

> valgrind ./a.out
==36468== Memcheck, a memory error detector
==36468== Copyright (C) 2002-2015, and GNU GPL'd, by Julian Seward et al.
==36468== Using Valgrind-3.12.0.SVN and LibVEX; rerun with -h for copyright   info
==36468== Command: ./a.out
==36468== 
Hello world
==36468== 
==36468== HEAP SUMMARY:
==36468==     in use at exit: 26,207 bytes in 190 blocks
==36468==   total heap usage: 264 allocs, 74 frees, 32,175 bytes allocated
==36468== 
==36468== LEAK SUMMARY:
==36468==    definitely lost: 0 bytes in 0 blocks
==36468==    indirectly lost: 0 bytes in 0 blocks
==36468==      possibly lost: 2,064 bytes in 1 blocks
==36468==    still reachable: 0 bytes in 0 blocks
==36468==         suppressed: 24,143 bytes in 189 blocks
==36468== Rerun with --leak-check=full to see details of leaked memory
==36468== 
==36468== For counts of detected and suppressed errors, rerun with: -v
==36468== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)

What's with the "possibly lost: 2,064 bytes in 1 blocks" and "suppressed: 24,143 bytes in 189 blocks"? I never used malloc so I'm not sure why this is happening.

Smith
  • 1
  • 2
  • This could be because it's a version of valgrind that has no suppressions for the current *glibc* version. Also, you need to say which OS it is, because valgrind runs on Linux and OS X. And it's common to see such false possitives on OS X. Additionally, if it's linux please explain how did you install valgrind and *glibc*. – Iharob Al Asimi Sep 17 '16 at 22:54
  • I't's in all likelihood a *false positive*. It's probably some code in the static library that does a one-time allocation of some memory that needs to live for the remainder of the process, and relies on being free'd when the process is terminated. – Some programmer dude Sep 17 '16 at 22:55
  • I'm using Mac OS X El Capitan 10.11.6. – Smith Sep 17 '16 at 23:03
  • Related if not a duplicate to: http://stackoverflow.com/q/12452541/694576 – alk Sep 18 '16 at 12:39

0 Answers0