Try to leak a bit less memory on proc and file operations

- Added lot of cleanup functions and code