Fixing memory leaks


(Sudarshan Venkataraman) #1

How much memory can we leak (using ‘khu’ on os161)? Zero? How do I go about identifying memory leaks? For instance, even consoletest leaks 1168 bytes. I cannot find anything in sys_write that I’ve malloc-ed and not freed.(Since the only thing that consoletest needs is the write system call). Any pointers (pun not intended) on how to proceed would be appreciated!
On a different note, when are we supposed to free/destroy file handles 0,1,2?


(Aakanksha Raika) #2

Are you freeing everything from the filetable ? I had that problem too , double checking file table fixed it for me. This includes console files(file 0 1 and 2).

You are suppose to free 0,1,2 when you destroy/free the file table.


(Sudarshan Venkataraman) #3

If we close file descriptors 0,1,2(when their reference count = 0), redirect test fails. If we don’t close them, then forktest-stability fails.


(Carl Nuessle) #4

To clarify: when a file table is destroyed, the references to any currently open file descriptors (file structs) should be removed. The descriptors them are shared objects and should not be cleaned up until there are no more existing references.

Secondly, regarding the above standard policy, console I/O (whether pre-populated by the kernel for the init process, inherited from init, or manually created later) should be no treated no differently from any other file descriptor (disk file, pipe etc.).


(Sudarshan Venkataraman) #5

I’m pretty much doing whatever you had mentioned , I will have to look into the gravity of “pretty much” over here , will give another look into it and get back ASAP.