Finding memory leakage issues with kmemleak
What is a memory leak and why does it matter? A memory leak is a situation where you have allocated memory dynamically but failed to free it. Well, you think you have succeeded in freeing it but the reality is that it hasn't been freed. The classic pedagogical case is a simple one like this (let's just make it a userspace example for simplicity):
static foo(void) {
char *ptr = malloc(1024);
/* ... work with it ... */
// forget to free it
}
Now, once you return from the function foo()
, it's basically impossible to free the memory pointed to by the variable ptr
. Why? You know it, ptr
is a local variable and is out of scope once you've returned from foo()
. Now, the 1,024 bytes of allocated memory is, in effect, locked up, inaccessible, wasted – we call this a leak. Of course, once the user process dies, it's freed back to...