简体   繁体   中英

Memory leaks without allocating any memory

I was just testing out some c code I was writing and I found that I had a lot of memory leaks, so I wanted to see where they were coming from. All the code I had was:

int main() {
    return 0;
}

Just a simple main that did nothing and I had all these memory leaks:

==38882== HEAP SUMMARY:
==38882==     in use at exit: 58,678 bytes in 363 blocks
==38882==   total heap usage: 514 allocs, 151 frees, 62,544 bytes allocated
==38882== 
==38882== LEAK SUMMARY:
==38882==    definitely lost: 8,624 bytes in 14 blocks
==38882==    indirectly lost: 1,168 bytes in 5 blocks
==38882==      possibly lost: 4,925 bytes in 68 blocks
==38882==    still reachable: 43,961 bytes in 276 blocks
==38882==         suppressed: 0 bytes in 0 blocks
==38882== Rerun with --leak-check=full to see details of leaked memory
==38882== 
==38882== For counts of detected and suppressed errors, rerun with: -v
==38882== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)

When I run this code on my university's computers I have no memory leaks. Is there something on my local machine that is causing this many memory leaks?

It is fine. Your program uses runtime library (ie libc or equivalent) and the library allocates some memory for own needs.

I get the same error on my Mac. It's either a valgrind problem or (more likely) a library problem on the Mac. I would suggest to use valgrind only on Linux.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM