Re: Question on Memory Leaks in Module

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Mit, 2008-01-23 at 18:31 +0530, Manish Katiyar wrote:
[...]
> So If i do a kzalloc() in my module and then unload my module without
> freeing it, it will be a memory leak...........Am i right ?? .. Or the

Yes.

> kernel is intelligent enough to check and free those memory buffers
> during unload of the module ?

No.
That is actually a not-trivial problem[0] as you want to kfree() a
buffer when the last pointer to it vanishes. And there is no way (except
explicit coding it that way) to e.g. have automatic reference-counting
like the typical scripting language (perl, php, ...) or Java.
For a kernel, there a lots of places where reference counting is just a
waste of memory and CPU power so no one needs/want's it there.

Next point is: Module unloading happens quite seldom in real life. So it
makes no sense to invest signifikant amount of work just for that one
operation (and there are voice who propose to never unload a module in
real life).
Next: Module unloading is not the only source of memory leaks. So you
have to make sure anyways that your module doesn't loose memory.
Typical error is to allocate memory in an open() sys-call-handler and
forget to free it on a close() handler.

	Bernd

[0]: Google for "garbage collection".
-- 
Firmix Software GmbH                   http://www.firmix.at/
mobil: +43 664 4416156                 fax: +43 1 7890849-55
          Embedded Linux Development and Services



--
To unsubscribe from this list: send an email with
"unsubscribe kernelnewbies" to ecartis@xxxxxxxxxxxx
Please read the FAQ at http://kernelnewbies.org/FAQ


[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux