Valgrind showing memory leak for printf and unused blocks

后端 未结 2 1179
天涯浪人
天涯浪人 2020-12-04 02:04
#include 
#include 
#include 

int main(int argc, char *argv[]){
  char *str = malloc(sizeof(char)*5);
  str = strcpy(         


        
相关标签:
2条回答
  • 2020-12-04 02:21

    Until the Valgrind team prioritizes OS X, you can safely assume that it will not give correct results on Apple systems running OS X versions newer than 10.7.

    On my Mavericks (10.9.5) machine, I still get the following warning from Valgrind (3.9.0)

    WARNING: Support on MacOS 10.8/10.9 is experimental and mostly broken.
    WARNING: Expect incorrect results, assertions and crashes.
    WARNING: In particular, Memcheck on 32-bit programs will fail to
    WARNING: detect any errors associated with heap-allocated data.
    

    For what it's worth, Valgrind 3.10.0 shows no leaks on my Debian Jessie installation.

    0 讨论(0)
  • 2020-12-04 02:28

    It isn't telling you that there is a leak:

    ==77215== LEAK SUMMARY:
    ==77215==    definitely lost: 0 bytes in 0 blocks
    ==77215==    indirectly lost: 0 bytes in 0 blocks
    ==77215==      possibly lost: 0 bytes in 0 blocks
    ==77215==    still reachable: 4,096 bytes in 1 blocks
    ==77215==         suppressed: 25,115 bytes in 373 blocks
    

    it's telling you that there is a block which is still reachable; whether or not there is a leak is dependent on your definition of 'leak'. What it does mean is that there is a pointer to the block somewhere.

    Refer to Still Reachable Leak detected by Valgrind for more information.

    0 讨论(0)
提交回复
热议问题