valgrind reporting non-freed blocks
Valgrind leak file summary:
ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)
malloc/free: in use at exit: 45,065 bytes in 12 blocks.
malloc/free: 161 allocs, 149 frees, 53,301 bytes allocated.
searching for pointers to 12 not-freed blocks.
checked 583,764 bytes.
One of this 12 blocks is from s开发者_如何学运维trdup
. I should have freed things allocated by strdup, I agree.
My question is, in general, is it bad to leave non-freed blocks? Is it called mem-leak technically?
Are they not given back to the system once program dies?
Please advise.
Edit 0: Thanks for your responses. How can I know where are these 12 non-freed blocks? And what part of code is generating them?
It is given back to the system.
It it not technically a memory leak if you have a reference to the memory. To be a memory leak you must de-reference the memory.
void *str = malloc(10);
str = NULL;
It is bad to leave non-freed blocks at any point. If the program is finishing it, it might not be that bad, but it is not good for any future change you might do (e.g.: extract a function and call it multiple times).
Also, getting rid of all memory leaks will make it easier to track with valgrind any new (and relevant) one.
Yes, it is bad to leave non-freed blocks. It's called memory-leak. If you let it your program will eventually use all available memory in your system. After program dies memory allocated by your program is freed.
精彩评论