4

Suppose I called kmalloc and didn't free that memory before rmmod was called on the module, what happens to that memory? Is it a memory leak and it is completely unusable until restart, or does the kernel free that memory automatically?

thanks

1 Answer 1

4

It won't be freed until explicitly done. Memory allocated with kmalloc() needs to be freed using kfree(). That piece of memory stays till the system is on.

[...] didn't free that memory before rmmod was called on the module [...]

When you do rmmod, module_exit() will be executed where you can free the memory incase when memory has to freed when module is unloaded. for example.

x() {
 z = kmalloc(...)
}
y() {
  kfree(z)
}
module_init(x)
module_exit(y)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .