Fixed memory leak in client and server cleanup code