fritzy / SleekXMPP

Python 2.6+/3.1+ XMPP Library
http://groups.google.com/group/sleekxmpp-discussion
Other
1.1k stars 299 forks source link

XEP-0050 leaks memory (session records) #155

Closed coffeeowl closed 12 years ago

coffeeowl commented 12 years ago

https://github.com/fritzy/SleekXMPP/blob/master/sleekxmpp/plugins/xep_0050/adhoc.py#L596 Here it sets session id to "client:"+some_id

    session = self.sessions[sessionid]
    sessionid = 'client:' + iq['command']['sessionid']
    session['id'] = iq['command']['sessionid']

    self.sessions[sessionid] = session

When it is time to remove session: https://github.com/fritzy/SleekXMPP/blob/master/sleekxmpp/plugins/xep_0050/adhoc.py#L571

    try:
        del self.sessions[session['id']]
    except:
        pass

nothing happens because it throws exception which is happily ignored. This works:

    try:
        del self.sessions['client:' + session['id']]
    except Exception, e:
        log.info("!!!! del exception, %s" % e)

session["id"] doesn't contain "client" string, while self.sessions does contain

I think it would be good to at least handle KeyError and output something meaningful to the log. It is considered to be bad practice to catch all exceptions (even system) and ignore them.

legastero commented 12 years ago

Thanks once again!