Valgrind showing memory leak for printf and unused blocks

后端 未结 2 1186
天涯浪人
天涯浪人 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: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.

提交回复
热议问题