Skip to content

Commit

Permalink
BUG: Free notifier after request handling (#6824)
Browse files Browse the repository at this point in the history
* BUG: Free notifier after request handling

If the request included `processEvents()` or otherwise
triggered the event loop the notifier could be
freed before the slot was finished, causing memory
corruption.

Fixes #6823

* ENH: Remove unneeded code in WebServer

As discussed in issue #6823, the code that explicily freed
instance variables wasn't really needed.  Removing the corresponding
code and a few other unused instance variables makes
the code cleaner.
  • Loading branch information
pieper authored and jcfr committed Feb 21, 2023
1 parent 9b45f4d commit 3345f6d
Showing 1 changed file with 0 additions and 13 deletions.
13 changes: 0 additions & 13 deletions Modules/Scripted/WebServer/WebServer.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,8 +294,6 @@ def __init__(self, server_address=("", 2016), requestHandlers=None, docroot='.',
self.socket.settimeout(5.)
if logMessage:
self.logMessage = logMessage
self.notifiers = {}
self.connections = {}
self.requestCommunicators = {}
self.enableCORS = enableCORS

Expand Down Expand Up @@ -334,10 +332,6 @@ def registerRequestHandler(self, handler):
self.requestHandlers.append(handler)
handler.logMessage = self.logMessage

def onReadableComplete(self):
self.logMessage("reading complete, freeing notifier")
self.readNotifier = None

def onReadable(self, fileno):
self.logMessage('Reading...')
requestHeader = b""
Expand Down Expand Up @@ -383,7 +377,6 @@ def onReadable(self, fileno):
self.logMessage('Got complete message of header size %d, body size %d' % (len(requestHeader), len(requestBody)))
self.readNotifier.disconnect('activated(int)', self.onReadable)
self.readNotifier.setEnabled(False)
qt.QTimer.singleShot(0, self.onReadableComplete)

if len(self.requestSoFar) == 0:
self.logMessage("Ignoring empty request")
Expand Down Expand Up @@ -462,11 +455,6 @@ def onReadable(self, fileno):
self.writeNotifier = qt.QSocketNotifier(fileno, qt.QSocketNotifier.Write)
self.writeNotifier.connect('activated(int)', self.onWritable)

def onWriteableComplete(self):
self.logMessage("writing complete, freeing notifier")
self.writeNotifier = None
self.connectionSocket = None

def onWritable(self, fileno):
self.logMessage('Sending on %d...' % (fileno))
sendError = False
Expand All @@ -482,7 +470,6 @@ def onWritable(self, fileno):
if self.sentSoFar >= self.toSend or sendError:
self.writeNotifier.disconnect('activated(int)', self.onWritable)
self.writeNotifier.setEnabled(False)
qt.QTimer.singleShot(0, self.onWriteableComplete)
self.connectionSocket.close()
self.logMessage('closed fileno %d' % (fileno))

Expand Down

0 comments on commit 3345f6d

Please sign in to comment.