From: Zoltan F. <zol...@us...> - 2003-01-15 16:26:50
|
Martin Sjögren wrote: > > Er. I don't think I understand you. Are there still versions of your > program that leak, even with the CVS version of pyopenssl? I wouldn't be > surprised, as I'm definitely not sure if I manage to free all the memory > allocated by openssl (the non-existant documentation is very vague on > reference counting and allocation). > > Please explain, ideally with a minimal program that still leaks. ;) > i'll try :) the server that still leaks is something like this: class server: def getmessage(self, timeout=None): rfds = self.client_co_list[:] rfds.insert(0, self.self_co) rs, ws, es = select.select(rfds, [], [], timeout) if rs == []: return 'no message' if rs.count(self.self_co): client_co, client_addr = self.self_co.accept() self.client_co_list.insert(0, client_co) return 'new connection' client_co = rs[0] client_id = client_co.fileno() raw_data = recvdata(client_co) if len(raw_data) == 0: self.client_co_list.remove(client_co) client_co.shutdown() client_co.close() return 'disconnect' return raw_data def serveclients(self): while True: message = self.getmessage() print message self.self_co of course is the Connection object the server listens on. now if the clients of this server are connecting/disconnecting fast enough, the disconnecting clients will not be deleted from the client_co_list until there are no new clients connecting, as if there are, they will be served before anything else, because the first object of the rfds is the server's Connection object, and one getmessage call will serve only the first object the select call returns. in this case (if the clients are connecting/disconnecting fast enough) this code still leaks if the connection objects are SSL objects, using simple sockets there is no leak at all. oh, and i just realising that i did not test the minimal server of the examples of the CVS version (or at least i can not recall its result). but the 0.5.1 version's example server does leak if the shutdown method is'nt commented out, and the clients are connecting/disconnecting fast enough. zoltan |