Fixed a memory leak when the server is being stopped.