2

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

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)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.