~sschwarzer/ftputil#21: 
Memory leaks using a modified session

If you create a modified session, for example, to specify a port to connect... You create a connection with this session and you try to do a list_dir, for example, if this operation fails, you catch the exception but the session object increments its reference counting and cannot be deleted by the garbage collector... Every time you do this operation in a loop and the exception is raised, the reference grows... The code should be something like:

class MySession:
 def __init__(self, host, port, user, passwd):
        ftplib.FTP.__init__(self)
        self.connect(host, port)
        self.login(user, passwd)

 
 self.conn = ftputil.FTPHost(m,
                             source_ftp_port,
                             source_ftp_user,
                             source_ftp_pass)
                             session_factory=MySession)
 try:
   self.conn.listdir('adir')
 except:
   pass
 del self.conn
Status
RESOLVED INVALID
Submitter
ftputiluser (unverified)
Assigned to
No-one
Submitted
16 years ago
Updated
16 years ago
Labels
bug library

schwa (unverified) 16 years ago · edit

Hello Antonio,

Thanks for your bug report - but I need more information. ;-) I can't see how the garbage collecting should be different when you use the default ftplib.FTP for the session_factory or a derived class, as long as the derived class doesn't contain bugs related to memory management.

The second thing is that ftputil is pure Python code, so at least I wouldn't expect bugs due to reference counting on the ​C/Python API level. I know of ​possible problems in the garbage collection even if only Python code is involved, however, ftputil 2.2.2 contains only one __del__ method (in FTPHost).

I recommend two things:

  • Please try your problematic code with the latest ftputil version. Your bug report states to be for version 2.0.1, which is quite old.

  • If the problem still persists, please attach a small example program to this issue which reproduces the problem. (Of course, you should remove all confidential information, such as user id or password.) You may use the ​debugging functionality of the gc module to show that there's memory which can't be freed.

schwa (unverified) 16 years ago · edit

I now set this bug's resolution to "invalid". There may be a bug, but I still need more information to reproduce it, if that's possible. If you still have problems regarding this issue, please reopen it.

Register here or Log in to comment, or comment via email.